diff --git a/base/src/org/adempiere/pipo/AbstractElementHandler.java b/base/src/org/adempiere/pipo/AbstractElementHandler.java new file mode 100644 index 0000000000..a6664aecf3 --- /dev/null +++ b/base/src/org/adempiere/pipo/AbstractElementHandler.java @@ -0,0 +1,376 @@ +/****************************************************************************** + * 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 javax.xml.transform.sax.TransformerHandler; + +import org.compiere.model.MSequence; +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.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{ + String recordLayout; + int id = 0; + TransformerHandler hd_document = getDocument(ctx); + AttributesImpl attsOut = getDocumentAttributes(ctx); + if (success == 1){ + //hd_documemt.startElement("","","Successfull",attsOut); + recordLayout = "Type:"+objectType + " - Name:"+objectName + " - ID:"+objectID +" - Action:"+objectStatus+" - Success"; + + hd_document.startElement("","","Success",attsOut); + hd_document.characters(recordLayout.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 = MSequence.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx)); + + StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail" + + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " + + "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," + + " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" + + "VALUES(" + + " "+ 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(), 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 = "Type:"+objectType + " - Name:"+tableName + " - ID:"+objectID +" - Action:"+objectStatus+" - Failure"; + //hd_documemt.startElement("","","Success",attsOut); + hd_document.characters(recordLayout.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 = MSequence.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx)); + + StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail" + + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " + + "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," + + " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" + + "VALUES(" + + " "+ 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 + + "', 'Failure'" + + ", "+objectID + + ", "+objectIDBackup + + ", '"+tableName + + "', "+AD_Table_ID + +")"); + 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); + 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 = MSequence.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" + + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " + + "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," + + " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" + + "VALUES(" + + " "+ Env.getAD_Client_ID(ctx) + + ", "+ Env.getAD_Org_ID(ctx) + + ", "+ Env.getAD_User_ID(ctx) + + ", "+ Env.getAD_User_ID(ctx) + + ", " + idBackup + + ", " + idDetail + + ", " + getPackageImpId(ctx) + + ", " + tableID + + ", " + columnID + + ", " + referenceID + + ", '" + (colValue != null ? colValue : from.get_Value(i)) + +"')"); + + 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("Can't find file "); + + 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("Can't find file "); + + 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."); + System.out.println(e.toString()); + + success = -1; + } + return success; + } + + protected int getClientId(Properties ctx) { + return Env.getContextAsInt(ctx, "AD_Client_ID"); + } + + protected int getPackageImpId(Properties ctx) { + return Env.getContextAsInt(ctx, "AD_Package_Imp_ID"); + } + + protected String getUpdateMode(Properties ctx) { + return Env.getContext(ctx, "UpdateMode"); + } + + protected String getTrxName(Properties ctx) { + return Env.getContext(ctx, "TrxName"); + } + + protected TransformerHandler getDocument(Properties ctx) { + return (TransformerHandler)ctx.get("Document"); + } + + protected AttributesImpl getDocumentAttributes(Properties ctx) { + return (AttributesImpl)ctx.get("DocumentAttributes"); + } + + protected String getPackageDirectory(Properties ctx) { + return Env.getContext(ctx, "PackageDirectory"); + } +} diff --git a/base/src/org/adempiere/pipo/Element.java b/base/src/org/adempiere/pipo/Element.java new file mode 100644 index 0000000000..4a4acebd94 --- /dev/null +++ b/base/src/org/adempiere/pipo/Element.java @@ -0,0 +1,60 @@ +/****************************************************************************** + * 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 org.xml.sax.Attributes; + +/** + * XML element structure + * @author Low Heng Sin + * + */ +public class Element { + + public String uri; + public String localName; + public String qName; + //element attributes + public Attributes attributes; + //defer for later reprocessing + public boolean defer = false; + + /** + * @param uri + * @param localName + * @param qName + * @param attributes + */ + public Element(String uri, String localName, String qName, Attributes attributes) { + this.uri = uri; + this.localName = localName; + this.qName = qName; + this.attributes = attributes; + } + + /** + * @return elementValue + */ + public String getElementValue() { + String elementValue = null; + if ("".equals (uri)) + elementValue = qName; + else + elementValue = uri + localName; + return elementValue; + } +} diff --git a/base/src/org/adempiere/pipo/ElementHandler.java b/base/src/org/adempiere/pipo/ElementHandler.java new file mode 100644 index 0000000000..4eef64dd1f --- /dev/null +++ b/base/src/org/adempiere/pipo/ElementHandler.java @@ -0,0 +1,56 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.xml.sax.SAXException; + +/** + * Interface for handling import and export of table data to xml + * @author Low Heng Sin + * + */ +public interface ElementHandler { + + /** + * Handle start of xml element ( import ). + * @param ctx + * @param element + * @throws org.xml.sax.SAXException + */ + public void startElement (Properties ctx, Element element) + throws org.xml.sax.SAXException; + + /** + * Handle closing of xml element ( import ). + * @param ctx + * @param element + * @throws SAXException + */ + public void endElement (Properties ctx, Element element) throws SAXException; + + /** + * Create xml element ( export ). + * @param ctx + * @param document + * @throws SAXException + */ + public void create(Properties ctx, TransformerHandler document) throws SAXException; +} diff --git a/base/src/org/adempiere/pipo/IDFinder.java b/base/src/org/adempiere/pipo/IDFinder.java new file mode 100644 index 0000000000..e96b9efdcc --- /dev/null +++ b/base/src/org/adempiere/pipo/IDFinder.java @@ -0,0 +1,240 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.logging.Level; + +import org.compiere.util.CLogger; +import org.compiere.util.DB; + +/** + * Utility class for the looking up of record id. + * @author Low Heng Sin + * + */ +public class IDFinder { + + private static CLogger log = CLogger.getCLogger(IDFinder.class); + + /** + * Get ID from Name for a table. + * TODO: substitute with PO.getAllIDs + * + * @param tableName + * @param name + * @param AD_Client_ID + * @param trxName + * + */ + public static int get_ID (String tableName, String name, int AD_Client_ID, String trxName) { + int id = 0; + StringBuffer sqlB = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where name=?"); + + if (!tableName.startsWith("AD_")) + sqlB = sqlB.append(" and AD_Client_ID=?"); + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), trxName); + pstmt.setString(1, name); + if (!tableName.startsWith("AD_")) + pstmt.setInt(2, AD_Client_ID); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) + id = rs.getInt(1); + rs.close(); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("get_ID:"+e); + } + return id; + } + + /** + * Get ID from column value for a table. + * + * @param tableName + * @param columName + * @param value + * @param AD_Client_ID + * @param trxName + */ + public static int get_IDWithColumn (String tableName, String columnName, Object value, int AD_Client_ID, String trxName) { + int id = 0; + StringBuffer sqlB = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where UPPER("+columnName+")=?"); + //StringBuffer sqlC = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where "+columnName+"="+value.toString()); + + if (!tableName.startsWith("AD_")) + sqlB = sqlB.append(" and AD_Client_ID=?"); + //here! + sqlB = sqlB.append(" Order By "+tableName+"_ID"); + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), trxName); + if (value instanceof String) + pstmt.setString(1, ((String)value).toUpperCase()); + else if (value instanceof Integer) + pstmt.setInt(1, ((Integer)value).intValue()); + if (!tableName.startsWith("AD_")) + pstmt.setInt(2, AD_Client_ID); + + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) + id = rs.getInt(1); + rs.close(); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("get_ID:"+e); + } + return id; + } + + /** + * Get ID from Name for a table with a Master reference. + * + * @param tableName + * @param name + * @param tableNameMaster + * @param nameMaster + * @param trxName + */ + public static int get_IDWithMaster (String tableName, String name, String tableNameMaster, String nameMaster, String trxName) { + int id = 0; + StringBuffer sqlB = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where UPPER(name)=? and " + + tableNameMaster+"_ID = (select "+tableNameMaster+"_ID from "+tableNameMaster+" where UPPER(name)=?)"); + + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), trxName); + pstmt.setString(1, name.toUpperCase()); + pstmt.setString(2, nameMaster.toUpperCase()); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) + id = rs.getInt(1); + rs.close(); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("get_IDWithMaster:"+e); + } + return id; + } + + /** + * Get ID from Name for a table with a Master reference. + * + * @param tableName + * @param name + * @param tableNameMaster + * @param masterID + * @param trxName + */ + + public static int get_IDWithMasterAndColumn (String tableName, String columnName, String name, String tableNameMaster, int masterID, String trxName) { + int id = 0; + StringBuffer sqlB = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where UPPER("+columnName+")=? and " + + tableNameMaster+"_ID =?"); + //StringBuffer sqlC = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where "+columnName+"="+name+" and " + // + tableNameMaster+"_ID ="+masterID); + log.info(sqlB.toString()); + + try { + + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), trxName); + pstmt.setString(1, name.toUpperCase()); + pstmt.setInt(2, masterID); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) + id = rs.getInt(1); + rs.close(); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("get_IDWithMasterAndColumn:"+e); + } + return id; + } + + /** + * Get ID from Name for a table with a Master reference ID. + * + * @param tableName + * @param name + * @param tableNameMaster + * @param masterID + * @param trxName + */ + public static int get_IDWithMaster (String tableName, String name, String tableNameMaster, int masterID, String trxName) { + int id = 0; + StringBuffer sqlB = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where name=? and " + + tableNameMaster+"_ID=?"); + + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), trxName); + pstmt.setString(1, name); + pstmt.setInt(2, masterID); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) + id = rs.getInt(1); + rs.close(); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("get_IDWithMasterID:"+e); + } + return id; + } + + /** + * Get ID from Name for a table. + * TODO: substitute with PO.getAllIDs + * + * @param tableName + * @param name + * @param AD_Client_ID + * @param trxName + */ + public static int getIDbyName (String tableName, String name, int AD_Client_ID, String trxName) { + int id = 0; + String sql = "SELECT "+tableName+"_ID " + + "FROM "+tableName+" " + + "WHERE name=?"; + if (!tableName.startsWith("AD_")) + sql = sql + " AND AD_Client_ID=?"; + try { + PreparedStatement pstmt = DB.prepareStatement(sql, trxName); + pstmt.setString(1, name); + if (!tableName.startsWith("AD_")) + pstmt.setInt(2, AD_Client_ID); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) + id = rs.getInt(1); + rs.close(); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.log(Level.SEVERE, "getID:"+e); + } + return id; + } +} diff --git a/base/src/org/adempiere/pipo/PackInHandler.java b/base/src/org/adempiere/pipo/PackInHandler.java index e7e382df2d..c911058010 100644 --- a/base/src/org/adempiere/pipo/PackInHandler.java +++ b/base/src/org/adempiere/pipo/PackInHandler.java @@ -14,26 +14,25 @@ * 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.math.BigDecimal; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Properties; -import java.sql.*; +import java.util.Stack; import java.io.*; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.logging.Level; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.sax.TransformerHandler; @@ -44,12 +43,50 @@ import javax.xml.transform.TransformerConfigurationException; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; -import org.compiere.Adempiere; +import org.adempiere.pipo.handler.CodeSnipitElementHandler; +import org.adempiere.pipo.handler.ColumnElementHandler; +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.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.WorkbenchElementHandler; +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.*; -import org.compiere.wf.*; import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.CLogger; +import org.compiere.util.Trx; import org.xml.sax.Attributes; import org.xml.sax.helpers.DefaultHandler; @@ -70,77 +107,132 @@ public class PackInHandler extends DefaultHandler { * PackInHandler Handler */ public PackInHandler () { - + setupHandlers(); } // PackInHandler - private X_AD_Menu m_Menu; // MMenu not used to avoid auto creation of AD_TREENODEMM - private MWindow m_Window = null; - private MPreference m_Preference = null; - private MProcess m_Process = null; - private X_AD_Process_Para m_Process_para = null; - private MTask m_Task = null; - private MForm m_Form = null; - private MMessage m_Message = null; - private X_AD_Workbench m_Workbench = null; - private X_AD_WorkbenchWindow m_Workbenchwindow = null; - private X_AD_Reference m_Reference = null; - private X_AD_Ref_List m_Ref_List = null; - private X_AD_PrintFormatItem m_PrintFormatItem = null; - private X_AD_PrintFormat m_PrintFormat = null; - private X_AD_ImpFormat m_ImpFormat = null; - private X_AD_ImpFormat_Row m_ImpFormat_row = null; - private X_AD_ReportView m_Reportview = null; - private X_AD_ReportView_Col m_Reportview_Col = null; - private X_AD_Val_Rule m_ValRule = null; - private MTable m_Table = null; - private MWorkflow m_Workflow = null; - private MWFNode m_WFNode = null; - private MWFNodeNext m_WFNodeNext = null; - private MWFNextCondition m_WFNodeNextCondition = null; - private MRole m_Role = null; - private MColumn m_Column = null; - private MTab m_Tab; - private MField m_Field = null; - private String d_menu[][] = new String [100][16]; - private int menu_seq=0; - /** Original Values */ - public Object[] m_oldValue = null; - /** New Valies */ - public Object[] m_newValue = null; /** Set this if you want to update Dictionary */ - public String m_UpdateMode = "true"; - String packageDirectory = null; - public String m_DatabaseType = "Oracle"; + private String m_UpdateMode = "true"; + private String packageDirectory = null; + private String m_DatabaseType = "Oracle"; private boolean adempiereAD = false; - private boolean adempieredata = false; - private String d_tablename = null; - private String d_rowname = null; - private GenericPO genericPO = null; - private HashMap defaults = new HashMap(); - StringBuffer sqlB = null; private int m_AD_Client_ID = 0; - int AD_Package_Imp_ID=0; - int AD_Package_Imp_Inst_ID=0; - int AD_Backup_ID =0; + private int AD_Package_Imp_ID=0; + private int AD_Package_Imp_Inst_ID=0; private CLogger log = CLogger.getCLogger("PackIn"); - OutputStream fw_document = null; - private TransformerHandler hd_documemt = null; + private OutputStream fw_document = null; + private TransformerHandler hd_document = null; private AttributesImpl attsOut = null; private StreamResult streamResult_document = null; private SAXTransformerFactory tf_document = null; private Transformer serializer_document = null; private int Start_Doc = 0; - private String Object_Status = null; private String logDate = null; private String PK_Status = "Installing"; - String fileDate = null; - boolean force = true; // This is set to true if the "-f" option - // is specified on the command line. - String fileSeperator=null; // transaction name private String m_trxName = null; private Properties m_ctx = null; + private Maphandlers = null; + private List menus = new ArrayList(); + private List defer = new ArrayList(); + private Stack stack = new Stack(); + + private void init() throws SAXException { + PackIn pack = new PackIn(); + packageDirectory = pack.m_Package_Dir; + m_UpdateMode = pack.m_UpdateMode; + m_DatabaseType = pack.m_Database; + File file = new File(""); + 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 { + hd_document = tf_document.newTransformerHandler(); + } catch (TransformerConfigurationException e2) { + log.info ("startElement:"+e2); + } + serializer_document = hd_document.getTransformer(); + serializer_document.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); + serializer_document.setOutputProperty(OutputKeys.INDENT,"yes"); + hd_document.setResult(streamResult_document); + hd_document.startDocument(); + attsOut = new AttributesImpl(); + attsOut.clear(); + hd_document.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("workbench", new WorkbenchElementHandler()); + 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()); + } /** * Receive notification of the start of an element. @@ -154,44 +246,9 @@ public class PackInHandler extends DefaultHandler { public void startElement (String uri, String localName, String qName, Attributes atts) throws org.xml.sax.SAXException { -// Create the package log + // Create the package log if (Start_Doc==0){ - PackIn pack = new PackIn(); - packageDirectory = pack.m_Package_Dir; - m_UpdateMode = pack.m_UpdateMode; - m_DatabaseType = pack.m_Database; - File file = new File(""); - fileSeperator = file.separator; - SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssZ"); - SimpleDateFormat formatter_log = new SimpleDateFormat("MM/dd/yy HH:mm:ss"); - Date today = new Date(); - fileDate = formatter_file.format(today); - logDate = formatter_log.format(today); - - String file_document = packageDirectory+fileSeperator+"doc"+fileSeperator+"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 { - hd_documemt = tf_document.newTransformerHandler(); - } catch (TransformerConfigurationException e2) { - log.info ("startElement:"+e2); - } - serializer_document = hd_documemt.getTransformer(); - serializer_document.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); - serializer_document.setOutputProperty(OutputKeys.INDENT,"yes"); - hd_documemt.setResult(streamResult_document); - hd_documemt.startDocument(); - attsOut = new AttributesImpl(); - attsOut.clear(); - hd_documemt.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\""); - Start_Doc=1; + init(); } // Check namespace. String elementValue = null; @@ -205,40 +262,40 @@ public class PackInHandler extends DefaultHandler { log.info("adempiereAD updateMode="+m_UpdateMode); adempiereAD = true; //Start package log - hd_documemt.startElement("","","adempiereDocument",attsOut); - hd_documemt.startElement("","","header",attsOut); - hd_documemt.characters((atts.getValue("Name")+" Install Log").toCharArray(),0,(atts.getValue("Name")+" Install Log").length()); - hd_documemt.endElement("","","header"); - hd_documemt.startElement("","","H3",attsOut); - hd_documemt.characters(("Package Name:" ).toCharArray(),0,("Package Name:" ).length()); - hd_documemt.endElement("","","H3"); - hd_documemt.startElement("","","packagename4log",attsOut); - hd_documemt.characters(atts.getValue("Name").toCharArray(),0,atts.getValue("Name").length()); - hd_documemt.endElement("","","packagename4log"); - hd_documemt.startElement("","","H3",attsOut); - hd_documemt.characters(("Version:" ).toCharArray(),0,("Version:" ).length()); - hd_documemt.endElement("","","H3"); - hd_documemt.startElement("","","Version",attsOut); - hd_documemt.characters(atts.getValue("Version").toCharArray(),0,atts.getValue("Version").length()); - hd_documemt.endElement("","","Version"); - hd_documemt.startElement("","","H3",attsOut); - hd_documemt.characters(("Package Install Date:" ).toCharArray(),0,("Package Install Date:" ).length()); - hd_documemt.endElement("","","H3"); - hd_documemt.startElement("","","installDate",attsOut); - hd_documemt.characters(logDate.toCharArray(),0,logDate.length()); - hd_documemt.endElement("","","installDate"); - hd_documemt.startElement("","","H3",attsOut); - hd_documemt.characters(("Min. Compiere Version:" ).toCharArray(),0,("Min. Compiere Version:" ).length()); - hd_documemt.endElement("","","H3"); - hd_documemt.startElement("","","CompVer",attsOut); - hd_documemt.characters(atts.getValue("CompVer").toCharArray(),0,atts.getValue("CompVer").length()); - hd_documemt.endElement("","","CompVer"); - hd_documemt.startElement("","","H3",attsOut); - hd_documemt.characters(("Min. Database Date:" ).toCharArray(),0,("Min. Database Date:" ).length()); - hd_documemt.endElement("","","H3"); - hd_documemt.startElement("","","DataBase",attsOut); - hd_documemt.characters(atts.getValue("DataBase").toCharArray(),0,atts.getValue("DataBase").length()); - hd_documemt.endElement("","","DataBase"); + hd_document.startElement("","","adempiereDocument",attsOut); + hd_document.startElement("","","header",attsOut); + hd_document.characters((atts.getValue("Name")+" Install Log").toCharArray(),0,(atts.getValue("Name")+" Install Log").length()); + hd_document.endElement("","","header"); + hd_document.startElement("","","H3",attsOut); + hd_document.characters(("Package Name:" ).toCharArray(),0,("Package Name:" ).length()); + hd_document.endElement("","","H3"); + hd_document.startElement("","","packagename4log",attsOut); + hd_document.characters(atts.getValue("Name").toCharArray(),0,atts.getValue("Name").length()); + hd_document.endElement("","","packagename4log"); + hd_document.startElement("","","H3",attsOut); + hd_document.characters(("Version:" ).toCharArray(),0,("Version:" ).length()); + hd_document.endElement("","","H3"); + hd_document.startElement("","","Version",attsOut); + hd_document.characters(atts.getValue("Version").toCharArray(),0,atts.getValue("Version").length()); + hd_document.endElement("","","Version"); + hd_document.startElement("","","H3",attsOut); + hd_document.characters(("Package Install Date:" ).toCharArray(),0,("Package Install Date:" ).length()); + hd_document.endElement("","","H3"); + hd_document.startElement("","","installDate",attsOut); + hd_document.characters(logDate.toCharArray(),0,logDate.length()); + hd_document.endElement("","","installDate"); + hd_document.startElement("","","H3",attsOut); + hd_document.characters(("Min. Compiere Version:" ).toCharArray(),0,("Min. Compiere Version:" ).length()); + hd_document.endElement("","","H3"); + hd_document.startElement("","","CompVer",attsOut); + hd_document.characters(atts.getValue("CompVer").toCharArray(),0,atts.getValue("CompVer").length()); + hd_document.endElement("","","CompVer"); + hd_document.startElement("","","H3",attsOut); + hd_document.characters(("Min. Database Date:" ).toCharArray(),0,("Min. Database Date:" ).length()); + hd_document.endElement("","","H3"); + hd_document.startElement("","","DataBase",attsOut); + hd_document.characters(atts.getValue("DataBase").toCharArray(),0,atts.getValue("DataBase").length()); + hd_document.endElement("","","DataBase"); createImp_Sum_table ("AD_Package_Imp_Backup"); createImp_Sum_table ("AD_Package_Imp"); @@ -253,28 +310,28 @@ public class PackInHandler extends DefaultHandler { AD_Package_Imp_ID = MSequence.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp", null); - sqlB = new StringBuffer ("Insert INTO AD_Package_Imp" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_PACKAGE_IMP_ID, RELEASENO, PK_VERSION, VERSION " - + ", DESCRIPTION, NAME, CREATOR" - + ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + AD_Package_Imp_ID - + ", '" + atts.getValue("CompVer") - + "', '" + atts.getValue("Version") - + "', '" + atts.getValue("DataBase") - + "', '" + atts.getValue("Description").replaceAll("'","''").replaceAll(",","") - + "', '" + atts.getValue("Name") - + "', '" + atts.getValue("creator") - + "', '" + atts.getValue("creatorcontact") - + "', '" + atts.getValue("createddate") - + "', '" + atts.getValue("updateddate") - + "', '" + PK_Status - +"')"); + 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("'","''").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) @@ -284,28 +341,28 @@ public class PackInHandler extends DefaultHandler { AD_Package_Imp_Inst_ID = MSequence.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" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_PACKAGE_IMP_INST_ID, RELEASENO, PK_VERSION, VERSION " - + ", DESCRIPTION, NAME, CREATOR" - + ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + AD_Package_Imp_Inst_ID - + ", '" + atts.getValue("CompVer") - + "', '" + atts.getValue("Version") - + "', '" + atts.getValue("DataBase") - + "', '" + atts.getValue("Description").replaceAll("'","''").replaceAll(",","") - + "', '" + atts.getValue("Name") - + "', '" + atts.getValue("creator") - + "', '" + atts.getValue("creatorcontact") - + "', '" + atts.getValue("createddate") - + "', '" + atts.getValue("updateddate") - + "', '" + PK_Status - +"')"); + 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("'","''").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); @@ -322,3032 +379,30 @@ public class PackInHandler extends DefaultHandler { 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("Document", hd_document); + m_ctx.put("DocumentAttributes", attsOut); } - // adempieredata element. - // some fields i.e. "table" are commons. - else if (elementValue.equals("adempieredata") || elementValue.equals("data")) { - log.info(elementValue); - adempieredata = true; - if (atts.getValue("clientname") != null) { - m_AD_Client_ID = get_ID("AD_Client", atts.getValue("clientname")); - Env.setContext(m_ctx, "AD_Client_ID", m_AD_Client_ID); - log.info("adempieredata: client set to "+m_AD_Client_ID+" "+atts.getValue("clientname")); - } + else if (elementValue.equals("menu")) { + //defer + Element e = new Element(uri, localName, qName, atts); + menus.add(e); } - else if (elementValue.equals("menu")) { - log.info(elementValue+" "+atts.getValue("ADMenuNameID")); - //String entitytype = atts.getValue("EntityType"); - //if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode == true ) { - - d_menu[menu_seq][0] = atts.getValue("ADMenuNameID"); - d_menu[menu_seq][1] = atts.getValue("ADWindowNameID"); - d_menu[menu_seq][2] = atts.getValue("ADProcessNameID"); - d_menu[menu_seq][3] = atts.getValue("ADFormNameID"); - d_menu[menu_seq][4] = atts.getValue("ADTaskNameID"); - d_menu[menu_seq][5] = atts.getValue("ADWorkbenchNameID"); - d_menu[menu_seq][6] = atts.getValue("ADWorkflowNameID"); - d_menu[menu_seq][7] = (atts.getValue("Action") != null ? atts.getValue("Action") : " "); - d_menu[menu_seq][8] = atts.getValue("Description").replaceAll("'","''").replaceAll(",",""); - d_menu[menu_seq][9] = atts.getValue("EntityType"); - d_menu[menu_seq][10] = atts.getValue("isReadOnly"); - d_menu[menu_seq][11] = atts.getValue("isSOTrx"); - d_menu[menu_seq][12] = atts.getValue("isSummary"); - d_menu[menu_seq][13] = atts.getValue("ADParentMenuNameID"); - d_menu[menu_seq][14] = atts.getValue("ADParentSeqno"); - d_menu[menu_seq][15] = atts.getValue("isActive"); - menu_seq=menu_seq+1; - //} - } - // window element. - else if (elementValue.equals("window")) { - log.info(elementValue+" "+atts.getValue("Name")); - String entitytype = atts.getValue("EntityType"); - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0 ) { - String name = atts.getValue("Name"); - int id= get_ID("AD_Window", name); - m_Window = new MWindow(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Window",m_Window); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_Window.setName(name); - name = atts.getValue("ADImageNameID"); - id = get_IDWithColumn("AD_Image", "Name", name); - m_Window.setAD_Image_ID(id); - name = atts.getValue("ADColorNameID"); - id = get_IDWithColumn("AD_Color", "Name", name); - m_Window.setAD_Color_ID(id); - m_Window.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Window.setEntityType(atts.getValue("EntityType")); - m_Window.setHelp (atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); - m_Window.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Window.setIsBetaFunctionality(Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue()); - m_Window.setIsDefault(Boolean.valueOf(atts.getValue("isDefault")).booleanValue()); - m_Window.setIsSOTrx(Boolean.valueOf(atts.getValue("isSOTrx")).booleanValue()); - m_Window.setName (atts.getValue("Name")); - m_Window.setProcessing (false); - //m_Window.setWinHeight(Integer.parseInt(atts.getValue("WinHeight"))); - //m_Window.setWinWidth (Integer.parseInt(atts.getValue("WinWidth"))); - m_Window.setWindowType (atts.getValue("WindowType")); - if (m_Window.save(m_trxName) == true){ - record_log (1, m_Window.getName(),"Window", m_Window.get_ID(),AD_Backup_ID, Object_Status,"AD_Window",get_IDWithColumn("AD_Table", "TableName", "AD_Window")); - } - else{ - record_log (0, m_Window.getName(),"Window", m_Window.get_ID(),AD_Backup_ID, Object_Status,"AD_Window",get_IDWithColumn("AD_Table", "TableName", "AD_Window")); - } - } - } -// preference element. - else if (elementValue.equals("preference")) { - log.info(elementValue); - //TODO Add User_ID - int windowid = get_ID("AD_Window", atts.getValue("ADWindowNameID")); - sqlB = new StringBuffer ("select AD_Preference_ID from AD_Preference where " - + " Attribute = '"+atts.getValue("Attribute") +"'" - + " and AD_Window_ID = ?"); - int id = DB.getSQLValue(m_trxName, sqlB.toString (), windowid); - m_Preference = new MPreference(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Preference",m_Preference); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - sqlB = null; - m_Preference.setAD_Window_ID(windowid); - m_Preference.setAttribute(atts.getValue("Attribute")); - m_Preference.setValue(atts.getValue("Value")); - if (m_Preference.save(m_trxName) == true){ - record_log (1, m_Preference.getAttribute(),"Preference", m_Preference.get_ID(),AD_Backup_ID, Object_Status,"AD_Preference",get_IDWithColumn("AD_Table", "TableName", "AD_Preference")); - } - else{ - record_log (0, m_Preference.getAttribute(),"Preference", m_Preference.get_ID(),AD_Backup_ID, Object_Status,"AD_Preference",get_IDWithColumn("AD_Table", "TableName", "AD_Preference")); - } - } - // tab element. - else if (elementValue.equals("tab")) { - log.info(elementValue+" "+atts.getValue("ADTabNameID")); - String entitytype = atts.getValue("EntityType"); - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0) { - - String name = atts.getValue("ADTabNameID"); - int tableid = get_IDWithColumn("AD_Table", "TableName", atts.getValue("ADTableNameID")); - int windowid = get_ID("AD_Window", atts.getValue("ADWindowNameID")); - sqlB = new StringBuffer ("select AD_Tab_ID from AD_Tab where AD_Window_ID = " + windowid - + " and Name = '"+name +"'" - + " and AD_Table_ID = ?"); - - int id = DB.getSQLValue(m_trxName, sqlB.toString (), tableid); - m_Tab = new MTab(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Tab",m_Tab); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - sqlB = null; - m_Tab.setName(name); - id = 0; - if (atts.getValue("ADColumnSortYesNoNameID")!= null){ - name = atts.getValue("ADColumnSortYesNoNameID"); - id = get_IDWithColumn("AD_Column", "Name", name); - m_Tab.setAD_ColumnSortYesNo_ID(id); - } - if (atts.getValue("ADColumnSortOrderNameID")!= null){ - name = atts.getValue("ADColumnSortOrderNameID"); - id = get_IDWithColumn("AD_Column", "Name", name); - m_Tab.setAD_ColumnSortOrder_ID(id); - } - if (atts.getValue("ADImageNameID")!= null){ - name = atts.getValue("ADImageNameID"); - id = get_IDWithColumn("AD_Image", "Name", name); - m_Tab.setAD_Image_ID(id); - } - if (atts.getValue("ADProcessNameID")!= null){ - name = atts.getValue("ADProcessNameID"); - id = get_IDWithColumn("AD_Process", "Name", name); - m_Tab.setAD_Process_ID(id); - } - if (atts.getValue("ADTableNameID")!= null){ - name = atts.getValue("ADTableNameID"); - id = get_IDWithColumn("AD_Table", "TableName", name); - m_Tab.setAD_Table_ID(id); - } - if (atts.getValue("ADColumnNameID")!= null){ - name = atts.getValue("ADColumnNameID"); - id = get_IDWithMasterAndColumn ("AD_Column","Name", atts.getValue("ADColumnNameID"), "AD_Table", get_IDWithColumn("AD_Table", "TableName", atts.getValue("ADTableNameID"))); - m_Tab.setAD_Column_ID(id); - } - if (atts.getValue("ADWindowNameID")!= null){ - name = atts.getValue("ADWindowNameID"); - id = get_IDWithColumn("AD_Window", "Name", name); - m_Tab.setAD_Window_ID(id); - } - if (atts.getValue("IncludedTabNameID")!= null){ - name = atts.getValue("IncludedTabNameID"); - id = get_IDWithColumn("AD_Tab", "Name", name); - m_Tab.setIncluded_Tab_ID(id); - } - m_Tab.setCommitWarning(atts.getValue("CommitWarning")); - m_Tab.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Tab.setEntityType (atts.getValue("EntityType")); - m_Tab.setHasTree(Boolean.valueOf(atts.getValue("isHasTree")).booleanValue()); - m_Tab.setHelp (atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); - m_Tab.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Tab.setImportFields (atts.getValue("ImportFields")); - m_Tab.setIsInfoTab (Boolean.valueOf(atts.getValue("isInfoTab")).booleanValue()); - m_Tab.setIsReadOnly (Boolean.valueOf(atts.getValue("isReadOnly")).booleanValue()); - m_Tab.setIsSingleRow (Boolean.valueOf(atts.getValue("isSingleRow")).booleanValue()); - m_Tab.setIsSortTab (Boolean.valueOf(atts.getValue("isSortTab")).booleanValue()); - m_Tab.setIsTranslationTab (Boolean.valueOf(atts.getValue("IsTranslationTab")).booleanValue()); - m_Tab.setName (atts.getValue("Name")); - m_Tab.setOrderByClause (atts.getValue("OrderByClause")); - m_Tab.setProcessing(false); - m_Tab.setSeqNo (Integer.parseInt(atts.getValue("SeqNo"))); - m_Tab.setTabLevel (Integer.parseInt(atts.getValue("TabLevel"))); - m_Tab.setWhereClause (atts.getValue("WhereClause")); - if (atts.getValue("ReadOnlyLogic") != null) { - m_Tab.setReadOnlyLogic(atts.getValue("ReadOnlyLogic")); - } - if (atts.getValue("DisplayLogic") != null) { - m_Tab.setDisplayLogic(atts.getValue("DisplayLogic")); - } - if (atts.getValue("isInsertRecord") != null) { - m_Tab.setIsInsertRecord(Boolean.valueOf(atts.getValue("isInsertRecord")).booleanValue()); - } - if (atts.getValue("isAdvancedTab") != null) { - m_Tab.setIsAdvancedTab(Boolean.valueOf(atts.getValue("isAdvancedTab")).booleanValue()); - } - if (m_Tab.save(m_trxName) == true){ - record_log (1, m_Tab.getName(),"Tab", m_Tab.get_ID(),AD_Backup_ID, Object_Status,"AD_Tab",get_IDWithColumn("AD_Table", "TableName", "AD_Tab")); - } else { - record_log (0, m_Tab.getName(),"Tab", m_Tab.get_ID(),AD_Backup_ID, Object_Status,"AD_Tab",get_IDWithColumn("AD_Table", "TableName", "AD_Tab")); - } - - } - } - // field element. - else if (elementValue.equals("field")) { - log.info(elementValue+" "+atts.getValue("Name")); - String entitytype = atts.getValue("EntityType"); - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0) { - String name = atts.getValue("Name"); - String tabname = atts.getValue("ADTabNameID"); - String colname = atts.getValue("ADColumnNameID"); -// log.info("Column Name ->"+colname); -// log.info("Database Name ->"+m_DatabaseType); - /** - //Adjust for difference between Oracle and PostgreSql DataTypes - if (m_DatabaseType.equals("Oracle")){ - if (colname.equals("TIMESTAMP")) - colname = "Date"; - else if (colname.equals("TIMESTAMP+Time")) - colname = "Date+Time"; - else if (colname.equals("NUMERIC")) - colname = "Number";} - else if (m_DatabaseType.equals("Sybase")){ - if (colname.equals("TIMESTAMP")) - colname = "Date"; - else if (colname.equals("TIMESTAMP+Time")) - colname = "Date+Time"; - else if (colname.equals("NUMERIC")) - colname = "Number";} - else if (m_DatabaseType.equals("PostgreSQL")){ - log.info("Before Column Name ->"+colname); - if (colname.equals("Date")) - colname = "TIMESTAMP"; - else if (colname.equals("Date+Time")) - colname = "TIMESTAMP+Time"; - else if (colname.equals("Number")) - colname = "NUMERIC"; - log.info("After Column Name ->"+colname); } - **/ - int tableid = get_IDWithColumn("AD_Table", "TableName", atts.getValue("ADTableNameID")); - int windowid = get_ID("AD_Window", atts.getValue("ADWindowNameID")); - //log.info("Column Name ->"+colname); - int columnid = get_IDWithMasterAndColumn ("AD_Column","ColumnName", colname, "AD_Table", tableid); - //log.info("ColumnID->"+columnid); - sqlB = new StringBuffer ("select AD_Tab_ID from AD_Tab where AD_Window_ID = " + windowid - + " and Name = '"+tabname +"'" - + " and AD_Table_ID = ?"); - int tabid = DB.getSQLValue(m_trxName, sqlB.toString (), tableid); - - if (tabid > 0 ) - { - - sqlB = new StringBuffer ("select AD_Field_ID from AD_Field where AD_Column_ID = "+columnid - + " and AD_Tab_ID = ?"); - int id = DB.getSQLValue(m_trxName, sqlB.toString (), tabid); - m_Field = new MField(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("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("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(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Field.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); - m_Field.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Field.setSortNo(new BigDecimal(atts.getValue("SortNo"))); - m_Field.setDisplayLogic(atts.getValue("DisplayLogic")); - if (m_Field.save(m_trxName) == true){ - record_log (1, m_Field.getName(),"Field", m_Field.get_ID(),AD_Backup_ID, Object_Status,"AD_Field",get_IDWithColumn("AD_Table", "TableName", "AD_Field")); - } - else{ - record_log (0, m_Field.getName(),"Field", m_Field.get_ID(),AD_Backup_ID, Object_Status,"AD_Field",get_IDWithColumn("AD_Table", "TableName", "AD_Field")); - } - } - else - log.severe("Tab do not exist to field Name: "+ name); - - } - } - // process element. - else if (elementValue.equals("process")) { - log.info(elementValue+" "+atts.getValue("Name")); - int id = 0; - String entitytype = atts.getValue("EntityType"); - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0 ) { - String name = atts.getValue("Name"); - - - // Get New process. - id=get_ID("AD_Process", name); - - if (id > 0){ - m_Process = new MProcess(m_ctx, id, m_trxName); - AD_Backup_ID = copyRecord("AD_Process",m_Process); - Object_Status = "Update"; - } - else{ - m_Process = new MProcess(m_ctx, id, m_trxName); - id = MSequence.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Process", m_trxName); - m_Process.setAD_Process_ID(id); - Object_Status = "New"; - AD_Backup_ID =0; - } - m_Process.setName(name); - name = atts.getValue("ADWorkflowNameID"); - id = get_IDWithColumn("AD_Workflow", "Name", name); - - m_Process.setAD_Workflow_ID(id); - name = atts.getValue("ADProcessNameID"); - - name = atts.getValue("ADPrintFormatNameID"); - id = get_IDWithColumn("AD_PrintFormat", "Name", name); - m_Process.setAD_PrintFormat_ID(id); - name = atts.getValue("ADReportViewNameID"); - id = get_IDWithColumn("AD_ReportView", "Name", name); - m_Process.setAD_ReportView_ID(id); - m_Process.setAccessLevel(atts.getValue("AccessLevel")); - m_Process.setClassname(atts.getValue("Classname")); - m_Process.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Process.setEntityType(atts.getValue("EntityType")); - m_Process.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); - m_Process.setIsBetaFunctionality(Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue()); - m_Process.setIsDirectPrint(Boolean.valueOf(atts.getValue("isDirectPrint")).booleanValue()); - m_Process.setIsReport(Boolean.valueOf(atts.getValue("isReport")).booleanValue()); - m_Process.setName(atts.getValue("Name")); - - m_Process.setProcedureName(atts.getValue("ProcedureName")); - m_Process.setStatistic_Count(0); - m_Process.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Process.setStatistic_Seconds(0); - m_Process.setValue(atts.getValue("Value")); - m_Process.setWorkflowValue(atts.getValue("WorkflowValue")); - if (m_Process.save(m_trxName) == true){ - record_log (1, m_Process.getName(),"Process", m_Process.get_ID(),AD_Backup_ID, Object_Status,"AD_Process",get_IDWithColumn("AD_Table", "TableName", "AD_Process")); - } - else{ - record_log (0, m_Process.getName(),"Process", m_Process.get_ID(),AD_Backup_ID, Object_Status,"AD_Process",get_IDWithColumn("AD_Table", "TableName", "AD_Process")); - } - } - } - // processpara element. - else if (elementValue.equals("processpara")) { - log.info(elementValue+" "+atts.getValue("Name")); - - String entitytype = atts.getValue("EntityType"); - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0 ) { - String name = atts.getValue("Name"); - - int id = get_IDWithMaster("AD_Process_Para", name, "AD_Process", atts.getValue("ADProcessNameID")); - X_AD_Process_Para m_Process_para = new X_AD_Process_Para(m_ctx, id, m_trxName); - if (id>0){ - AD_Backup_ID = copyRecord("AD_Process_Para",m_Process_para); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_Process_para.setName(atts.getValue("Name")); - name = atts.getValue("ADProcessNameID"); - id = get_IDWithColumn("AD_Process", "Name", name); - m_Process_para.setAD_Process_ID(id); - name = atts.getValue("ADElementNameID"); - id = get_IDWithColumn("AD_Element", "Name", name); - m_Process_para.setAD_Element_ID(id); - name = atts.getValue("ADReferenceNameID"); - /** - //Adjust for difference between Oracle and PostgreSql DataTypes - if (m_DatabaseType.equals("Oracle")){ - if (name.equals("TIMESTAMP")) - name = "Date"; - else if (name.equals("TIMESTAMP+Time")) - name = "Date+Time"; - else if (name.equals("NUMERIC")) - name = "Number";} - else if (m_DatabaseType.equals("Sybase")){ - if (name.equals("TIMESTAMP")) - name = "Date"; - else if (name.equals("TIMESTAMP+Time")) - name = "Date+Time"; - else if (name.equals("NUMERIC")) - name = "Number";} - else if (m_DatabaseType.equals("PostgreSQL")){ - if (name.equals("Date")) - name = "TIMESTAMP"; - else if (name.equals("Date+Time")) - name = "TIMESTAMP+Time"; - else if (name.equals("Number")) - name = "NUMERIC";} - **/ - id = get_IDWithColumn("AD_Reference", "Name", name); - m_Process_para.setAD_Reference_ID(id); - name = atts.getValue("ADReferenceValueNameID"); - id = get_IDWithColumn("AD_Reference", "Name", name); - m_Process_para.setAD_Reference_Value_ID(id); - name = atts.getValue("ADValRuleNameID"); - id = get_IDWithColumn("AD_Val_Rule", "Name", name); - m_Process_para.setAD_Val_Rule_ID(id); - m_Process_para.setColumnName(atts.getValue("ColumnName")); - m_Process_para.setDefaultValue(atts.getValue("DefaultValue")); - m_Process_para.setDefaultValue2(atts.getValue("DefaultValue2")); - m_Process_para.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Process_para.setEntityType(atts.getValue("EntityType")); - m_Process_para.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); - m_Process_para.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Process_para.setName(atts.getValue("Name")); - m_Process_para.setVFormat(atts.getValue("VFormat")); - m_Process_para.setValueMax(atts.getValue("ValueMax")); - m_Process_para.setValueMin(atts.getValue("ValueMin")); - m_Process_para.setSeqNo(Integer.parseInt(atts.getValue("SeqNo"))); - m_Process_para.setFieldLength(Integer.parseInt(atts.getValue("FieldLength"))); - m_Process_para.setIsCentrallyMaintained(Boolean.valueOf(atts.getValue("isCentrallyMaintained")).booleanValue()); - m_Process_para.setIsMandatory(Boolean.valueOf(atts.getValue("isMandatory")).booleanValue()); - m_Process_para.setIsRange(Boolean.valueOf(atts.getValue("isRange")).booleanValue()); - if (m_Process_para.save(m_trxName) == true){ - record_log (1, m_Process_para.getName(),"Process_para", m_Process_para.get_ID(),AD_Backup_ID, Object_Status,"AD_Process_para",get_IDWithColumn("AD_Table", "TableName", "AD_Process_para")); - } - else{ - record_log (0, m_Process_para.getName(),"Process_para", m_Process_para.get_ID(),AD_Backup_ID, Object_Status,"AD_Process_para",get_IDWithColumn("AD_Table", "TableName", "AD_Process_para")); - } - } - } - else if (elementValue.equals("message")) { - log.info(elementValue+" "+atts.getValue("Value")); - String entitytype = atts.getValue("EntityType"); - if (entitytype.equals("U") || entitytype.equals("D") && m_UpdateMode.equals("true")) { - String value = atts.getValue("Value"); - int id = get_IDWithColumn("AD_Message", "value", value); - - m_Message = new MMessage(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Message",m_Message); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_Message.setMsgText(atts.getValue("MsgText").replaceAll("'","''").replaceAll(",","")); - m_Message.setMsgTip(atts.getValue("MsgTip").replaceAll("'","''").replaceAll(",","")); - m_Message.setEntityType(atts.getValue("EntityType")); - m_Message.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Message.setValue(value); - m_Message.setMsgType(atts.getValue("MsgType")); - if (m_Message.save(m_trxName) == true){ - record_log (1, m_Message.getValue(),"Message", m_Message.get_ID(),AD_Backup_ID, Object_Status,"AD_Message",get_IDWithColumn("AD_Message", "value", "AD_Message")); - } - else{ - record_log (0, m_Message.getValue(),"Message", m_Message.get_ID(),AD_Backup_ID, Object_Status,"AD_Message",get_IDWithColumn("AD_Message", "value", "AD_Message")); - } - } - } - else if (elementValue.equals("dynvalrule")) { - log.info(elementValue+" "+atts.getValue("Name")); - String entitytype = atts.getValue("EntityType"); - if (entitytype.equals("U") || entitytype.equals("D") && m_UpdateMode.equals("true")) { - String name = atts.getValue("Name"); - int id = get_IDWithColumn("AD_Val_Rule", "name", name); - - m_ValRule = new X_AD_Val_Rule(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Val_Rule",m_ValRule); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_ValRule.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_ValRule.setEntityType(atts.getValue("EntityType")); - m_ValRule.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_ValRule.setName(name); - m_ValRule.setType(atts.getValue("Type")); - m_ValRule.setCode(atts.getValue("Code")); - if (m_ValRule.save(m_trxName) == true){ - record_log (1, m_ValRule.getName(),"Task", m_ValRule.get_ID(),AD_Backup_ID, Object_Status,"AD_Val_Rule",get_IDWithColumn("AD_Val_Rule", "Name", "AD_Val_Rule")); - } - else{ - record_log (0, m_ValRule.getName(),"Task", m_ValRule.get_ID(),AD_Backup_ID, Object_Status,"AD_Val_Rule",get_IDWithColumn("AD_Val_Rule", "Name", "AD_Val_Rule")); - } - } - } - // workflow element. - else if (elementValue.equals("workflow")) { - log.info("In PackInHandler.java with element workflow"); - log.info(elementValue+" "+atts.getValue("Name")); - String entitytype = atts.getValue("EntityType"); - log.info("entitytype "+atts.getValue("EntityType")); - - if (entitytype.equals("U") || entitytype.equals("D") && m_UpdateMode.equals("true")) { - log.info("entitytype is a U or D"); - - String workflowName = atts.getValue("Name"); - - int id = get_IDWithColumn("AD_Workflow", "name", workflowName); - - m_Workflow = new MWorkflow(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Workflow",m_Workflow); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - - if (atts.getValue("ADWorkflowResponsibleNameID")!= null){ - String name = atts.getValue("ADWorkflowResponsibleNameID"); - id = get_IDWithColumn("AD_WF_Responsible", "Name", name); - m_Workflow.setAD_WF_Responsible_ID(id); - } - if (atts.getValue("ADTableNameID")!= null){ - String Name = atts.getValue("ADTableNameID"); - id = get_IDWithColumn("AD_Table", "TableName", Name); - m_Workflow.setAD_Table_ID(id); - - } - if (atts.getValue("ADWorkflowProcessorNameID")!= null){ - String Name = atts.getValue("ADWorkflowProcessorNameID"); - id = get_IDWithColumn("AD_WorkflowProcessor", "Name", Name); - m_Workflow.setAD_WorkflowProcessor_ID(id); - - } - m_Workflow.setName(workflowName); - m_Workflow.setAccessLevel (atts.getValue("AccessLevel")); - m_Workflow.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Workflow.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); - m_Workflow.setDurationUnit(atts.getValue("DurationUnit")); - m_Workflow.setAuthor(atts.getValue("Author")); - m_Workflow.setVersion(Integer.valueOf(atts.getValue("Version"))); - m_Workflow.setPriority(Integer.valueOf(atts.getValue("Priority"))); - m_Workflow.setLimit(Integer.valueOf(atts.getValue("Limit"))); - m_Workflow.setDuration(Integer.valueOf(atts.getValue("Duration"))); - m_Workflow.setCost(Integer.valueOf(atts.getValue("Cost"))); - m_Workflow.setWorkingTime(Integer.valueOf(atts.getValue("WorkingTime"))); - m_Workflow.setWaitingTime(Integer.valueOf(atts.getValue("WaitingTime"))); - m_Workflow.setPublishStatus(atts.getValue("PublishStatus")); - m_Workflow.setWorkflowType(atts.getValue("WorkflowType")); - m_Workflow.setDocValueLogic(atts.getValue("DocValueLogic")); - m_Workflow.setIsValid(atts.getValue("isValid") != null ? Boolean.valueOf(atts.getValue("isValid")).booleanValue():true); - m_Workflow.setEntityType(atts.getValue("EntityType")); - m_Workflow.setAD_WF_Node_ID(-1); -// log.info("in3"); - attsOut.clear(); - log.info("about to execute m_Workflow.save"); - if (m_Workflow.save(m_trxName) == true){ - log.info("m_Workflow save success"); - record_log (1, m_Workflow.getName(),"Workflow", m_Workflow.get_ID(),AD_Backup_ID, Object_Status,"AD_Workflow",get_IDWithColumn("AD_Workflow", "Name", "AD_Workflow")); - } - else{ - log.info("m_Workflow save failure"); - record_log (0, m_Workflow.getName(),"Workflow", m_Workflow.get_ID(),AD_Backup_ID, Object_Status,"AD_Workflow",get_IDWithColumn("AD_Workflow", "Name", "AD_Workflow")); - } - } else { - log.info("entitytype is not a U or D"); - - } - } - // workflowNode element. - else if (elementValue.equals("workflowNode")) { - log.info("In PackInHandler.java with element workflowNode"); - log.info(elementValue+" "+atts.getValue("Name")); - String entitytype = atts.getValue("EntityType"); - log.info("entitytype "+atts.getValue("EntityType")); - - if (entitytype.equals("U") || entitytype.equals("D") && m_UpdateMode.equals("true")) { - log.info("entitytype is a U or D"); - - String workflowName = atts.getValue("ADWorkflowNameID"); - - int workflowId = get_IDWithColumn("AD_Workflow", "name", workflowName); - - String workflowNodeName = atts.getValue("Name"); - - sqlB = new StringBuffer ("SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?"); - - int id = DB.getSQLValue(m_trxName,sqlB.toString(),workflowId,workflowNodeName); - - m_WFNode = new MWFNode(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_WF_Node",m_WFNode); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_WFNode.setName(workflowNodeName); - - String Name = atts.getValue("ADWorkflowNameID"); - id = get_IDWithColumn("AD_Workflow", "Name", Name); - m_WFNode.setAD_Workflow_ID(id); - if (atts.getValue("ADProcessNameID")!= null){ - Name = atts.getValue("ADProcessNameID"); - id = get_IDWithColumn("AD_Process", "Name", Name); - m_WFNode.setAD_Process_ID(id); - } - if (atts.getValue("ADFormNameID")!= null){ - String name = atts.getValue("ADFormNameID"); - id = get_IDWithColumn("AD_Form", "Name", name); - m_WFNode.setAD_Form_ID(id); - } - - if (atts.getValue("ADWorkflowResponsibleNameID")!= null){ - String name = atts.getValue("ADWorkflowResponsibleNameID"); - id = get_IDWithColumn("AD_WF_Responsible", "Name", name); - m_WFNode.setAD_WF_Responsible_ID(id); - } - - if (atts.getValue("ADWindowNameID")!= null){ - String name = atts.getValue("ADWindowNameID"); - id = get_IDWithColumn("AD_Window", "Name", name); - m_WFNode.setAD_Window_ID(id); - } - if (atts.getValue("ADImageNameID")!= null){ - String name = atts.getValue("ADImageNameID"); - id = get_IDWithColumn("AD_Image", "Name", name); - m_WFNode.setAD_Image_ID(id); - } - if (atts.getValue("ADWorkflowBlockNameID")!= null){ - String name = atts.getValue("ADWorkflowBlockNameID"); - id = get_IDWithColumn("AD_WF_Block", "Name", name); - m_WFNode.setAD_WF_Block_ID(id); - } - /* FIXME: Do we need TaskName ? - if (atts.getValue("ADTaskNameID")!=null){ - String name = atts.getValue("ADTaskNameID"); - sqlB = new StringBuffer ("SELECT AD_Task_ID FROM AD_Task WHERE Name= ?"); - taskid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - */ - m_WFNode.setEntityType(atts.getValue("EntityType")); - m_WFNode.setAction(atts.getValue("Action")); - m_WFNode.setDocAction(atts.getValue("DocAction")); - m_WFNode.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_WFNode.setJoinElement(atts.getValue("JoinElement")); - m_WFNode.setSplitElement(atts.getValue("SplitElement")); - m_WFNode.setXPosition(Integer.valueOf(atts.getValue("XPosition"))); - m_WFNode.setYPosition(Integer.valueOf(atts.getValue("YPosition"))); - m_WFNode.setWaitingTime(Integer.valueOf(atts.getValue("WaitingTime"))); - m_WFNode.setWaitTime(Integer.valueOf(atts.getValue("WaitTime"))); - m_WFNode.setWorkingTime(Integer.valueOf(atts.getValue("WorkingTime"))); - m_WFNode.setCost(new BigDecimal(atts.getValue("Cost"))); - m_WFNode.setDuration(Integer.valueOf(atts.getValue("Duration"))); - m_WFNode.setPriority(Integer.valueOf(atts.getValue("Priority"))); - //FIXME: Failing for some reason on a "" - //m_WFNode.setStartMode(atts.getValue("StartMode")); - //FIXME: Failing for some reason on a "" - //m_WFNode.setSubflowExecution(atts.getValue("SubflowExecution")); - m_WFNode.setIsCentrallyMaintained(Boolean.valueOf(atts.getValue("IsCentrallyMaintained")).booleanValue()); - m_WFNode.setDynPriorityChange(new BigDecimal(atts.getValue("DynPriorityChange"))); - //m_WFNode.setAccessLevel (atts.getValue("AccessLevel")); - //FIXME: Failing for some reason on a "" - //m_WFNode.setDynPriorityUnit (atts.getValue("DynPriorityUnit")); - m_WFNode.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); -// log.info("in3"); - attsOut.clear(); - log.info("about to execute m_WFNode.save"); - if (m_WFNode.save(m_trxName) == true){ - log.info("m_WFNode save success"); - record_log (1, m_WFNode.getName(),"WFNode", m_WFNode.get_ID(),AD_Backup_ID, Object_Status,"AD_WF_Node",get_IDWithColumn("AD_WF_Node", "Name", "AD_WF_Node")); - } - else{ - log.info("m_WFNode save failure"); - record_log (0, m_WFNode.getName(),"WFNode", m_WFNode.get_ID(),AD_Backup_ID, Object_Status,"AD_WF_Node",get_IDWithColumn("AD_WF_Node", "Name", "AD_WF_Node")); - } - } else { - log.info("entitytype is not a U or D"); - - } - } - // workflowNodeNext element. - else if (elementValue.equals("workflowNodeNext")) { - log.info("In PackInHandler.java with element workflowNodeNext"); - String entitytype = atts.getValue("EntityType"); - log.info("entitytype "+atts.getValue("EntityType")); - - if (entitytype.equals("U") || entitytype.equals("D") && m_UpdateMode.equals("true")) { - log.info("entitytype is a U or D"); - - - String workflowName = atts.getValue("ADWorkflowNameID"); - - int workflowId = get_IDWithColumn("AD_Workflow", "name", workflowName); - - String workflowNodeName = atts.getValue("ADWorkflowNodeNameID"); - String workflowNodeNextName = atts.getValue("ADWorkflowNodeNextNameID"); - - sqlB = new StringBuffer ("SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?"); - - int wfNodeId = DB.getSQLValue(m_trxName,sqlB.toString(),workflowId,workflowNodeName); - - int wfNodeNextId = DB.getSQLValue(m_trxName,sqlB.toString(),workflowId,workflowNodeNextName); - - sqlB = new StringBuffer ("SELECT ad_wf_nodenext_id FROM AD_WF_NodeNext WHERE ad_wf_node_id =? and ad_wf_next_id =?"); - - //int id = get_IDWithColumn("AD_WF_Node", "name", workflowNodeName); - int id = DB.getSQLValue(m_trxName,sqlB.toString(),wfNodeId,wfNodeNextId); - - m_WFNodeNext = new MWFNodeNext(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_WF_NodeNext",m_WFNodeNext); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_WFNodeNext.setAD_WF_Node_ID(wfNodeId); - m_WFNodeNext.setAD_WF_Next_ID(wfNodeNextId); - m_WFNodeNext.setEntityType(atts.getValue("EntityType")); - m_WFNodeNext.setSeqNo(Integer.valueOf(atts.getValue("SeqNo"))); - m_WFNodeNext.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_WFNodeNext.setIsStdUserWorkflow(atts.getValue("IsStdUserWorkflow") != null ? Boolean.valueOf(atts.getValue("IsStdUserWorkflow")).booleanValue():true); -// log.info("m_WFNodeNext.get_ID: " + String.valueOf(m_WFNodeNext.get_ID)); - attsOut.clear(); - log.info("about to execute m_WFNodeNext.save"); - if (m_WFNodeNext.save(m_trxName) == true){ - log.info("m_WFNodeNext save success"); - record_log (1, String.valueOf(m_WFNodeNext.get_ID()),"WFNodeNext", m_WFNodeNext.get_ID(),AD_Backup_ID, Object_Status,"AD_WF_NodeNext",get_IDWithColumn("AD_WF_NodeNext", "ad_wf_nodenext_id", "AD_WF_NodeNext")); - } - else{ - log.info("m_WFNodeNext save failure"); - record_log (0, String.valueOf(m_WFNodeNext.get_ID()),"WFNode", m_WFNodeNext.get_ID(),AD_Backup_ID, Object_Status,"AD_WF_NodeNext",get_IDWithColumn("AD_WF_NodeNext", "ad_wf_nodenext_id", "AD_WF_NodeNext")); - } - } else { - log.info("entitytype is not a U or D"); - - } - } - // workflowNodeNextCondition element. - else if (elementValue.equals("workflowNodeNextCondition")) { - log.info("In PackInHandler.java with element workflowNodeNextCondition"); - String entitytype = atts.getValue("EntityType"); - log.info("entitytype "+atts.getValue("EntityType")); - - if (entitytype.equals("U") || entitytype.equals("D") && m_UpdateMode.equals("true")) { - log.info("entitytype is a U or D"); - - - String workflowName = atts.getValue("ADWorkflowNameID"); - - int workflowId = get_IDWithColumn("AD_Workflow", "name", workflowName); - - String workflowNodeName = atts.getValue("ADWorkflowNodeNameID"); - String workflowNodeNextName = atts.getValue("ADWorkflowNodeNextNameID"); - - sqlB = new StringBuffer ("SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?"); - - int wfNodeId = DB.getSQLValue(m_trxName,sqlB.toString(),workflowId,workflowNodeName); - - int wfNodeNextId = DB.getSQLValue(m_trxName,sqlB.toString(),workflowId,workflowNodeNextName); - - sqlB = new StringBuffer ("SELECT ad_wf_nodenext_id FROM AD_WF_NodeNext WHERE ad_wf_node_id =? and ad_wf_next_id =?"); - int wfNodeNextTablePKId = DB.getSQLValue(m_trxName,sqlB.toString(),wfNodeId,wfNodeNextId); - - sqlB = new StringBuffer ("SELECT ad_wf_nextcondition_id FROM AD_WF_NextCondition WHERE ad_wf_nodenext_id =?"); - int id = DB.getSQLValue(m_trxName,sqlB.toString(),wfNodeNextTablePKId); - - m_WFNodeNextCondition = new MWFNextCondition(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_WF_NextCondition",m_WFNodeNextCondition); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - - sqlB = new StringBuffer ("SELECT AD_Column.ad_column_id FROM AD_Column, AD_Table WHERE AD_Column.ad_table_id = AD_Table.ad_table_id and AD_Table.name = '" + atts.getValue("ADTableNameID") + "' and AD_Column.name = ?"); - //int columnId = DB.getSQLValue(m_trxName,sqlB.toString(),atts.getValue("ADTableNameID"), atts.getValue("ADColumnNameID")); - int columnId = DB.getSQLValue(m_trxName,sqlB.toString(),atts.getValue("ADColumnNameID")); - m_WFNodeNextCondition.setAD_Column_ID(columnId); - - m_WFNodeNextCondition.setAD_WF_NodeNext_ID(wfNodeNextTablePKId); - m_WFNodeNextCondition.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_WFNodeNextCondition.setAD_WF_NodeNext_ID(wfNodeNextTablePKId); - m_WFNodeNextCondition.setSeqNo(Integer.valueOf(atts.getValue("SeqNo"))); - m_WFNodeNextCondition.setEntityType(atts.getValue("EntityType")); - m_WFNodeNextCondition.setAndOr(atts.getValue("AndOr")); - m_WFNodeNextCondition.setOperation(atts.getValue("Operation")); - m_WFNodeNextCondition.setValue(atts.getValue("Value")); - m_WFNodeNextCondition.setValue2(atts.getValue("Value2")); - attsOut.clear(); - log.info("about to execute m_WFNodeNextCondition.save"); - if (m_WFNodeNextCondition.save(m_trxName) == true){ - log.info("m_WFNodeNextCondition save success"); - record_log (1, String.valueOf(m_WFNodeNextCondition.get_ID()),"WFNextCondition", m_WFNodeNextCondition.get_ID(),AD_Backup_ID, Object_Status,"AD_WF_NextCondition",get_IDWithColumn("AD_WF_NextCondition", "ad_wf_nextcondition_id", "AD_WF_NextCondition")); - } - else{ - log.info("m_WFNodeNextCondition save failure"); - record_log (0, String.valueOf(m_WFNodeNextCondition.get_ID()),"WFNextCondition", m_WFNodeNextCondition.get_ID(),AD_Backup_ID, Object_Status,"AD_WF_NextCondition",get_IDWithColumn("AD_WF_NextCondition", "ad_wf_nextcondition_id", "AD_WF_NextCondition")); - } - } else { - log.info("entitytype is not a U or D"); - - } - } - // table element. - else if (elementValue.equals("table")) { - log.info(elementValue+" "+atts.getValue("ADTableNameID")); - String entitytype = atts.getValue("EntityType"); - - if (entitytype.equals("U") || entitytype.equals("D") && m_UpdateMode.equals("true")) { - - String tableName = atts.getValue("ADTableNameID"); - - int id = get_IDWithColumn("AD_Table", "TableName", tableName); - - m_Table = new MTable(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Table",m_Table); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_Table.setTableName(tableName); - String Name = atts.getValue("ADWindowNameID"); - id = get_IDWithColumn("AD_Window", "Name", Name); - m_Table.setAD_Window_ID(id); - Name = atts.getValue("POWindowNameID"); - if (Name != null){ - id = get_IDWithColumn("AD_Window", "Name", Name); - m_Table.setPO_Window_ID(id); - } - else - Name = atts.getValue("ADValRuleNameID"); - id = get_IDWithColumn("AD_Val_Rule", "Name", Name); - - m_Table.setAD_Val_Rule_ID(id); - m_Table.setAccessLevel (atts.getValue("AccessLevel")); - m_Table.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Table.setEntityType(atts.getValue("EntityType")); - m_Table.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); - m_Table.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Table.setImportTable(atts.getValue("ImportTable")); - m_Table.setIsChangeLog(Boolean.valueOf(atts.getValue("isChangeLog")).booleanValue()); - m_Table.setIsDeleteable(Boolean.valueOf(atts.getValue("isDeleteable")).booleanValue()); - m_Table.setIsHighVolume(Boolean.valueOf(atts.getValue("isHighVolume")).booleanValue()); - m_Table.setIsSecurityEnabled(Boolean.valueOf(atts.getValue("isSecurityEnabled")).booleanValue()); - m_Table.setIsView(Boolean.valueOf(atts.getValue("isView")).booleanValue()); - //m_Table.setLoadSeq(Integer.parseInt(atts.getValue("LoadSeq"))); - m_Table.setName(atts.getValue("Name")); - m_Table.setReplicationType(atts.getValue("ReplicationType")); - m_Table.setTableName(atts.getValue("TableName")); -// log.info("in3"); - attsOut.clear(); - if (m_Table.save(m_trxName) == true){ - record_log (1, m_Table.getName(),"Table", m_Table.get_ID(),AD_Backup_ID, Object_Status,"AD_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Table")); - } - else{ - record_log (0, m_Table.getName(),"Table", m_Table.get_ID(),AD_Backup_ID, Object_Status,"AD_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Table")); - } - } - } - // column element. - else if (elementValue.equals("column")) { - log.info(elementValue+" "+atts.getValue("ColumnName")); - int success=0; - String entitytype = atts.getValue("EntityType"); - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0 ) { - String columnName = atts.getValue("ColumnName"); - - int tableid = get_IDWithColumn("AD_Table", "TableName", atts.getValue("ADTableNameID")); - int id =get_IDWithMasterAndColumn ("AD_Column", "ColumnName", columnName, "AD_Table", tableid); - m_Column = new MColumn(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Column",m_Column); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_Column.setColumnName(columnName); - - String Name = atts.getValue("ADProcessNameID"); - id = get_IDWithColumn("AD_Process", "Name", Name); - m_Column.setAD_Process_ID(id); - Name = atts.getValue("ADReferenceNameID"); -// log.info("Column Name1 ->"+Name); -// log.info("Database Name ->"+m_DatabaseType); - /** - //Adjust for difference between Oracle and PostgreSql DataTypes - if (m_DatabaseType.equals("Oracle")){ - if (Name.equals("TIMESTAMP")) - Name = "Date"; - else if (Name.equals("TIMESTAMP+Time")) - Name = "Date+Time"; - else if (Name.equals("NUMERIC")) - Name = "Number";} - else if (m_DatabaseType.equals("Sybase")){ - if (Name.equals("TIMESTAMP")) - Name = "Date"; - else if (Name.equals("TIMESTAMP+Time")) - Name = "Date+Time"; - else if (Name.equals("NUMERIC")) - Name = "Number";} - else if (m_DatabaseType.equals("PostgreSQL")){ - if (Name.equals("Date")) - Name = "TIMESTAMP"; - else if (Name.equals("Date+Time")) - Name = "TIMESTAMP+Time"; - else if (Name.equals("Number")) - Name = "NUMERIC";} - **/ -// log.info("Column Name2 ->"+Name); - id = get_IDWithColumn("AD_Reference", "Name", Name); - m_Column.setAD_Reference_ID(id); -// log.info("Column ID ->"+id); - Name = atts.getValue("ADTableNameID"); - id = get_IDWithColumn("AD_Table", "TableName", Name); - m_Column.setAD_Table_ID(id); - - Name = atts.getValue("ADValRuleNameID"); - id = get_IDWithColumn("AD_Val_Rule", "Name", Name); - m_Column.setAD_Val_Rule_ID(id); - Name = atts.getValue("ADReferenceNameValueID"); - id = get_IDWithColumn("AD_Reference", "Name", Name); - m_Column.setAD_Reference_Value_ID(id); - m_Column.setCallout(atts.getValue("Callout")); - m_Column.setColumnSQL(atts.getValue("ColumnSQL")); - - m_Column.setColumnName(atts.getValue("ColumnName")); - m_Column.setDefaultValue(atts.getValue("DefaultValue")); - m_Column.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Column.setEntityType(atts.getValue("EntityType")); - - if (Integer.parseInt(atts.getValue("FieldLength")) >0) - m_Column.setFieldLength (Integer.parseInt(atts.getValue("FieldLength"))); - m_Column.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); - m_Column.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Column.setIsAlwaysUpdateable((Boolean.valueOf(atts.getValue("isAlwaysUpdateable")).booleanValue())); - //m_Column.setIsEncrypted(atts.getValue("isEncrypted")); - m_Column.setIsIdentifier((Boolean.valueOf(atts.getValue("isIdentifier")).booleanValue())); - m_Column.setIsKey((Boolean.valueOf(atts.getValue("isKey")).booleanValue())); - m_Column.setIsMandatory((Boolean.valueOf(atts.getValue("isMandatory")).booleanValue())); - - m_Column.setIsParent((Boolean.valueOf(atts.getValue("isParent")).booleanValue())); - m_Column.setIsSelectionColumn((Boolean.valueOf(atts.getValue("isSelectionColumn")).booleanValue())); - m_Column.setIsSyncDatabase (atts.getValue("getIsSyncDatabase")); - - m_Column.setIsTranslated((Boolean.valueOf(atts.getValue("isTranslated")).booleanValue())); - m_Column.setIsUpdateable((Boolean.valueOf(atts.getValue("isUpdateable")).booleanValue())); - m_Column.setName(atts.getValue("Name")); - m_Column.setReadOnlyLogic(atts.getValue("ReadOnlyLogic")); - - if (Integer.parseInt(atts.getValue("SeqNo")) >0) - m_Column.setSeqNo(Integer.parseInt(atts.getValue("SeqNo"))); - m_Column.setVFormat(atts.getValue("VFormat")); - if (atts.getValue("ValueMax") != null) - m_Column.setValueMax(atts.getValue("ValueMax")); - if (atts.getValue("ValueMin") != null) - m_Column.setValueMin(atts.getValue("ValueMin")); - if (atts.getValue("Version") != null) - m_Column.setVersion(new BigDecimal(atts.getValue("Version"))); - - // Setup Element. - id = get_IDWithColumn("AD_Element", "ColumnName", m_Column.getColumnName()); - X_AD_Element element = new X_AD_Element(m_ctx, id, m_trxName); - - String Object_Status_col = Object_Status; - if (element.getAD_Element_ID() == 0) { - //Object_Status = "New"; - element.setColumnName(m_Column.getColumnName()); - element.setEntityType(m_Column.getEntityType()); - element.setPrintName(m_Column.getColumnName()); - - element.setName(m_Column.getColumnName()); - if (element.save(m_trxName) == true){ - record_log (1, m_Column.getName(),"Element", element.getAD_Element_ID(),AD_Backup_ID, "New","AD_Element",get_IDWithColumn("AD_Table", "TableName", "AD_Element")); - } else { - record_log (0, m_Column.getName(),"Element", element.getAD_Element_ID(),AD_Backup_ID, "New","AD_Element",get_IDWithColumn("AD_Table", "TableName", "AD_Element")); - } - } - - Object_Status = Object_Status_col; - m_Column.setAD_Element_ID(element.getAD_Element_ID()); - - boolean recreateColumn = - ( - m_Column.is_new() - || m_Column.is_ValueChanged("AD_Reference_ID") - || m_Column.is_ValueChanged("FieldLength") - || m_Column.is_ValueChanged("ColumnName") - || m_Column.is_ValueChanged("IsMandatory") - ); - - // changed default ?? - // m_Column.is_ValueChanged("DefaultValue") doesn't work well with nulls - if (! recreateColumn) { - String oldDefault = (String) m_Column.get_ValueOld("DefaultValue"); - String newDefault = (String) m_Column.get_Value("DefaultValue"); - if (oldDefault != null && oldDefault.length() == 0) - oldDefault = null; - if (newDefault != null && newDefault.length() == 0) - newDefault = null; - if ((oldDefault == null && newDefault != null) || - (oldDefault != null && newDefault == null)) { - recreateColumn = true; - } else if (oldDefault != null && newDefault != null) { - if (! oldDefault.equals(newDefault)) - recreateColumn = true; - } - } - - // Don't create database column for virtual columns - // Don't create columns by default, just if getIsSyncDatabase='Y' - if (recreateColumn) { - String sync = atts.getValue("getIsSyncDatabase"); - if (m_Column.isVirtualColumn() || sync == null || (!sync.equals("Y"))) - recreateColumn = false; - } - - if (m_Column.save(m_trxName) == true){ - record_log (1, m_Column.getName(),"Column", m_Column.get_ID(),AD_Backup_ID, Object_Status,"AD_Column",get_IDWithColumn("AD_Table", "TableName", "AD_Column")); - } else { - record_log (0, m_Column.getName(),"Column", m_Column.get_ID(),AD_Backup_ID, Object_Status,"AD_Column",get_IDWithColumn("AD_Table", "TableName", "AD_Column")); - } - - if (recreateColumn) { - success = createcolumn (m_Column); - - if (success == 1){ - record_log (1, m_Column.getColumnName(),"dbColumn", m_Column.get_ID(),0, Object_Status,atts.getValue("ADTableNameID").toUpperCase(),get_IDWithColumn("AD_Table", "TableName", atts.getValue("ADTableNameID").toUpperCase())); - } else { - record_log (0, m_Column.getColumnName(),"dbColumn", m_Column.get_ID(),0, Object_Status,atts.getValue("ADTableNameID").toUpperCase(),get_IDWithColumn("AD_Table", "TableName", atts.getValue("ADTableNameID").toUpperCase())); - } - } - } - } - - // Role element. - else if (elementValue.equals("role")) { - log.info(elementValue+" "+atts.getValue("Name")); - - String name = atts.getValue("Name"); - - int id = get_ID("AD_Role", name); - m_Role = new MRole(m_ctx, id, m_trxName); - - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Role",m_Role); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - - m_Role.setName(name); - name = atts.getValue("treemenuname"); - if (name!= null){ - id = get_IDWithColumn("AD_Tree", "Name", name); - m_Role.setAD_Tree_Menu_ID(id); - } - - name = null; - name = atts.getValue("treeorgname"); - if (name!= null){ - id = get_IDWithColumn("AD_Tree", "Name", name); - m_Role.setAD_Tree_Org_ID(id); - } - - name = null; - name = atts.getValue("currencycode"); - if (name!= null){ - id = get_IDWithColumn("C_Currency", "ISO_Code", name); - m_Role.setC_Currency_ID(id); - } - - name = null; - name = atts.getValue("supervisorid"); - if (name!= null){ - id = get_IDWithColumn("AD_User", "Name", name); - m_Role.setC_Currency_ID(id); - } - - m_Role.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Role.setAmtApproval(new BigDecimal(atts.getValue("AmtApproval"))); - m_Role.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Role.setIsAccessAllOrgs(atts.getValue("isAccessAllOrgs") != null ? Boolean.valueOf(atts.getValue("isAccessAllOrgs")).booleanValue():true); - m_Role.setIsCanApproveOwnDoc(atts.getValue("isCanApproveOwnDoc") != null ? Boolean.valueOf(atts.getValue("isCanApproveOwnDoc")).booleanValue():true); - m_Role.setIsCanExport(atts.getValue("isCanExport") != null ? Boolean.valueOf(atts.getValue("isCanExport")).booleanValue():true); - m_Role.setIsCanReport(atts.getValue("isCanReport") != null ? Boolean.valueOf(atts.getValue("isCanReport")).booleanValue():true); - m_Role.setIsChangeLog(atts.getValue("isChangeLog") != null ? Boolean.valueOf(atts.getValue("isChangeLog")).booleanValue():true); - m_Role.setIsManual(atts.getValue("isManual") != null ? Boolean.valueOf(atts.getValue("isManual")).booleanValue():true); - m_Role.setIsPersonalAccess(atts.getValue("isPersonalAccess") != null ? Boolean.valueOf(atts.getValue("isPersonalAccess")).booleanValue():true); - m_Role.setIsPersonalLock(atts.getValue("isPersonalLock") != null ? Boolean.valueOf(atts.getValue("isPersonalLock")).booleanValue():true); - m_Role.setIsShowAcct(atts.getValue("isShowAcct") != null ? Boolean.valueOf(atts.getValue("isShowAcct")).booleanValue():true); - m_Role.setIsUseUserOrgAccess(atts.getValue("isUseUserOrgAccess") != null ? Boolean.valueOf(atts.getValue("isUseUserOrgAccess")).booleanValue():true); - m_Role.setOverwritePriceLimit(atts.getValue("isOverwritePriceLimit") != null ? Boolean.valueOf(atts.getValue("isOverwritePriceLimit")).booleanValue():true); - m_Role.setPreferenceType(atts.getValue("PreferenceType")); - m_Role.setUserLevel(atts.getValue("UserLevel")); - - if (m_Role.save(m_trxName) == true){ - - record_log (1, m_Role.getName(),"Role", m_Role.get_ID(),AD_Backup_ID, Object_Status,"AD_Role",get_IDWithColumn("AD_Table", "TableName", "AD_Role")); - } - else{ - - record_log (0, m_Role.getName(),"Role", m_Role.get_ID(),AD_Backup_ID, Object_Status,"AD_Role",get_IDWithColumn("AD_Table", "TableName", "AD_Role")); - } - } - - - else if (elementValue.equals("userrole")) { - log.info(elementValue); - int roleid =0; - int userid =0; - int orgid =0; - - if (atts.getValue("username")!=null){ - String name = atts.getValue("username"); - sqlB = new StringBuffer ("SELECT AD_User_ID FROM AD_User WHERE Name= ?"); - userid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - if (atts.getValue("rolename")!=null){ - String name = atts.getValue("rolename"); - sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); - roleid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - if (atts.getValue("orgname")!=null){ - String name = atts.getValue("orgname"); - sqlB = new StringBuffer ("SELECT AD_Org_ID FROM AD_Org WHERE Name= ?"); - orgid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - sqlB = new StringBuffer ("SELECT count(*) FROM AD_User_Roles WHERE AD_User_ID = ? and AD_Role_ID = ? and AD_Org_ID = "+orgid); - int count = DB.getSQLValue(m_trxName,sqlB.toString(),userid,roleid); - if (count>0){ - //AD_Backup_ID = copyRecord("AD_Role",m_Role); - Object_Status = "Update"; - sqlB = new StringBuffer ("UPDATE AD_User_Roles " - + "SET isActive = '" + atts.getValue("isActive")+"'" - + " WHERE AD_User_ID = " + userid - + " and AD_Role_ID = " + roleid - + " and AD_Org_ID = " + orgid ); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to user roles failed"); - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - sqlB = new StringBuffer ("Insert INTO AD_User_Roles" - + "(AD_Client_ID, CreatedBy, UpdatedBy, " - + "AD_User_ID, AD_Role_ID, AD_Org_ID, isActive) " - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " +userid - + ", " + roleid - + ", " + orgid - + ", '" + atts.getValue("isActive")+"')"); - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to user roles failed"); - } - } - - else if (elementValue.equals("orgrole")) { - log.info(elementValue); - int roleid =0; - int orgid =0; - - if (atts.getValue("rolename")!=null){ - String name = atts.getValue("rolename"); - sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); - roleid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - if (atts.getValue("orgname")!=null){ - String name = atts.getValue("orgname"); - sqlB = new StringBuffer ("SELECT AD_Org_ID FROM AD_Org WHERE Name= ?"); - orgid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - sqlB = new StringBuffer ("SELECT count(*) FROM AD_Role_OrgAccess WHERE AD_Role_ID=? and AD_Org_ID=?"); - int count = DB.getSQLValue(m_trxName,sqlB.toString(),roleid,orgid); - if (count>0){ - Object_Status = "Update"; - sqlB = new StringBuffer ("UPDATE AD_Role_OrgAccess " - + "SET isActive = '" + atts.getValue("isActive") - + "', isReadOnly = '" + atts.getValue("isReadOnly") - + "' WHERE AD_Role_ID = " + roleid - + " and AD_Org_ID = " + orgid ); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to org access failed"); - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - sqlB = new StringBuffer ("Insert INTO AD_Role_OrgAccess" - + "(AD_Client_ID, CreatedBy, UpdatedBy, " - + "AD_Role_ID, AD_Org_ID, isActive, isReadOnly) " - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + roleid - + ", " + orgid - + ", '" + atts.getValue("isActive") - + "', '" + atts.getValue("isReadOnly")+"')"); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to org access failed"); - } - } - - else if (elementValue.equals("windowaccess")) { - log.info(elementValue); - int roleid =0; - int windowid =0; - - if (atts.getValue("rolename")!=null){ - String name = atts.getValue("rolename"); - sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); - roleid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - if (atts.getValue("windowname")!=null){ - String name = atts.getValue("windowname"); - sqlB = new StringBuffer ("SELECT AD_Window_ID FROM AD_Window WHERE Name= ?"); - windowid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - sqlB = new StringBuffer ("SELECT count(*) FROM AD_Window_Access WHERE AD_Role_ID=? and AD_Window_ID=?"); - int count = DB.getSQLValue(m_trxName,sqlB.toString(),roleid,windowid); - if (count>0){ - Object_Status = "Update"; - sqlB = new StringBuffer ("UPDATE AD_Window_Access " - + "SET isActive = '" + atts.getValue("isActive") - + "', isReadWrite = '" + atts.getValue("isReadWrite") - + "' WHERE AD_Role_ID = " + roleid - + " and AD_Window_ID = " + windowid ); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to window access failed"); - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - sqlB = new StringBuffer ("Insert INTO AD_Window_Access" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_Role_ID, AD_Window_ID, isActive, isReadWrite) " - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + roleid - + ", " + windowid - + ", '" + atts.getValue("isActive") - + "', '" + atts.getValue("isReadWrite")+"')"); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to window access failed"); - } - } - - else if (elementValue.equals("processaccess")) { - log.info(elementValue); - int roleid =0; - int processid =0; - - if (atts.getValue("rolename")!=null){ - String name = atts.getValue("rolename"); - sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); - roleid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - if (atts.getValue("processname")!=null){ - String name = atts.getValue("processname"); - sqlB = new StringBuffer ("SELECT AD_Process_ID FROM AD_Process WHERE Name= ?"); - processid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - sqlB = new StringBuffer ("SELECT count(*) FROM AD_Process_Access WHERE AD_Role_ID=? and AD_Process_ID=?"); - int count = DB.getSQLValue(m_trxName,sqlB.toString(),roleid,processid); - if (count>0){ - Object_Status = "Update"; - sqlB = new StringBuffer ("UPDATE AD_Process_Access " - + "SET isActive = '" + atts.getValue("isActive") - + "', isReadWrite = '" + atts.getValue("isReadWrite") - + "' WHERE AD_Role_ID = " + roleid - + " and AD_Process_ID = " + processid ); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to process access failed"); - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - sqlB = new StringBuffer ("Insert INTO AD_Process_Access" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_Role_ID, AD_Process_ID, isActive, isReadWrite) " - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + roleid - + ", " + processid - + ", '" + atts.getValue("isActive") - + "', '" + atts.getValue("isReadWrite")+"')"); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to process access failed"); - } - } - - else if (elementValue.equals("formaccess")) { - log.info(elementValue); - int roleid =0; - int formid =0; - - if (atts.getValue("rolename")!=null){ - String name = atts.getValue("rolename"); - sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); - roleid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - if (atts.getValue("formname")!=null){ - String name = atts.getValue("formname"); - sqlB = new StringBuffer ("SELECT AD_Form_ID FROM AD_Process WHERE Name= ?"); - formid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - sqlB = new StringBuffer ("SELECT count(*) FROM AD_Form_Access WHERE AD_Role_ID=? and AD_Form_ID=?"); - int count = DB.getSQLValue(m_trxName,sqlB.toString(),roleid,formid); - if (count>0){ - Object_Status = "Update"; - sqlB = new StringBuffer ("UPDATE AD_Form_Access " - + "SET isActive = '" + atts.getValue("isActive") - + "', isReadWrite = '" + atts.getValue("isReadWrite") - + "' WHERE AD_Role_ID = " + roleid - + " and AD_Form_ID = " + formid ); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to form access failed"); - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - sqlB = new StringBuffer ("Insert INTO AD_Form_Access" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_Role_ID, AD_Form_ID, isActive, isReadWrite) " - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + roleid - + ", " + formid - + ", '" + atts.getValue("isActive") - + "', '" + atts.getValue("isReadWrite")+"')"); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to form access failed"); - } - } - - - else if (elementValue.equals("workflowaccess")) { - log.info(elementValue); - int roleid =0; - int workflowid =0; - - if (atts.getValue("rolename")!=null){ - String name = atts.getValue("rolename"); - sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); - roleid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - if (atts.getValue("workflowname")!=null){ - String name = atts.getValue("workflowname"); - sqlB = new StringBuffer ("SELECT AD_Workflow_ID FROM AD_Workflow WHERE Name= ?"); - workflowid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - sqlB = new StringBuffer ("SELECT count(*) FROM AD_Workflow_Access WHERE AD_Role_ID=? and AD_Workflow_ID=?"); - int count = DB.getSQLValue(m_trxName,sqlB.toString(),roleid,workflowid); - if (count>0){ - Object_Status = "Update"; - sqlB = new StringBuffer ("UPDATE AD_Workflow_Access " - + "SET isActive = '" + atts.getValue("isActive") - + "', isReadWrite = '" + atts.getValue("isReadWrite") - + "' WHERE AD_Role_ID = " + roleid - + " and AD_Workflow_ID = " + workflowid ); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to workflow access failed"); - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - sqlB = new StringBuffer ("Insert INTO AD_Workflow_Access" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_Role_ID, AD_Workflow_ID, isActive, isReadWrite) " - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + roleid - + ", " + workflowid - + ", '" + atts.getValue("isActive") - + "', '" + atts.getValue("isReadWrite")+"')"); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to workflow access failed"); - } - } - - else if (elementValue.equals("taskaccess")) { - log.info(elementValue); - int roleid =0; - int taskid =0; - - if (atts.getValue("rolename")!=null){ - String name = atts.getValue("rolename"); - sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); - roleid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - if (atts.getValue("taskname")!=null){ - String name = atts.getValue("taskname"); - sqlB = new StringBuffer ("SELECT AD_Task_ID FROM AD_Task WHERE Name= ?"); - taskid = DB.getSQLValue(m_trxName,sqlB.toString(),name); - } - - sqlB = new StringBuffer ("SELECT count(*) FROM AD_Task_Access WHERE AD_Role_ID=? and AD_Task_ID=?"); - int count = DB.getSQLValue(m_trxName,sqlB.toString(),roleid,taskid); - if (count>0){ - Object_Status = "Update"; - sqlB = new StringBuffer ("UPDATE AD_Task_Access " - + "SET isActive = '" + atts.getValue("isActive") - + "', isReadWrite = '" + atts.getValue("isReadWrite") - + "' WHERE AD_Role_ID = " + roleid - + " and AD_Task_ID = " + taskid ); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to task access failed"); - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - sqlB = new StringBuffer ("Insert INTO AD_Task_Access" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_Role_ID, AD_Task_ID, isActive, isReadWrite) " - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + roleid - + ", " + taskid - + ", '" + atts.getValue("isActive") - + "', '" + atts.getValue("isReadWrite")+"')"); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to task access failed"); - } - } - - - // task element. - else if (elementValue.equals("task")) { - log.info(elementValue+" "+atts.getValue("ADTaskNameID")); - String entitytype = atts.getValue("EntityType"); - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0 ) { - String name = atts.getValue("ADTaskNameID"); - int id = get_ID("AD_Task", name); - m_Task = new MTask(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Task",m_Task); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_Task.setAccessLevel(atts.getValue("AccessLevel")); - m_Task.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Task.setEntityType(atts.getValue("EntityType")); - m_Task.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); - m_Task.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Task.setName(name); - m_Task.setOS_Command(atts.getValue("OS_Command")); - if (m_Task.save(m_trxName) == true){ - record_log (1, m_Task.getName(),"Task", m_Task.get_ID(),AD_Backup_ID, Object_Status,"AD_Task",get_IDWithColumn("AD_Table", "TableName", "AD_Task")); - } - else{ - record_log (0, m_Task.getName(),"Task", m_Task.get_ID(),AD_Backup_ID, Object_Status,"AD_Task",get_IDWithColumn("AD_Table", "TableName", "AD_Task")); - } - } - } - // form element. - else if (elementValue.equals("form")) { - log.info(elementValue+" "+atts.getValue("ADFormNameID")); - - String entitytype = atts.getValue("EntityType"); - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0 ) { - String name = atts.getValue("ADFormNameID"); - int id = get_ID("AD_Form", name); - m_Form = new MForm(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Form",m_Form); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_Form.setClassname (atts.getValue("Classname")); - m_Form.setIsBetaFunctionality (Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue()); - m_Form.setAccessLevel(atts.getValue("AccessLevel")); - m_Form.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Form.setEntityType(atts.getValue("EntityType")); - m_Form.setHelp(atts.getValue("Help").replaceAll(",","")); - m_Form.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Form.setName(atts.getValue("Name")); - - if (m_Form.save(m_trxName) == true){ - record_log (1, m_Form.getName(),"Form", m_Form.get_ID(),AD_Backup_ID, Object_Status,"AD_Form",get_IDWithColumn("AD_Table", "TableName", "AD_Form")); - } - else{ - record_log (0, m_Form.getName(),"Form", m_Form.get_ID(),AD_Backup_ID, Object_Status,"AD_Form",get_IDWithColumn("AD_Table", "TableName", "AD_Form")); - } - } - } -// impformat element. - else if (elementValue.equals("impformat")) { - log.info(elementValue+" "+atts.getValue("Name")); - - int id = get_ID("AD_ImpFormat", atts.getValue("Name")); - m_ImpFormat = new X_AD_ImpFormat(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_ImpFormat",m_ImpFormat); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_ImpFormat.setName(atts.getValue("Name")); - String Name = atts.getValue("ADTableNameID"); - id = get_IDWithColumn("AD_Table", "TableName", Name); - m_ImpFormat.setAD_Table_ID(id); - m_ImpFormat.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_ImpFormat.setProcessing(atts.getValue("isProcessing") != null ? Boolean.valueOf(atts.getValue("isProcessing")).booleanValue():true); - m_ImpFormat.setName(atts.getValue("Name")); - m_ImpFormat.setDescription(atts.getValue("Description")); - m_ImpFormat.setFormatType(atts.getValue("FormatType")); - if (m_ImpFormat.save(m_trxName) == true){ - record_log (1, m_ImpFormat.getName(),"ImpFormat", m_ImpFormat.get_ID(),AD_Backup_ID, Object_Status,"AD_ImpFormat",get_IDWithColumn("AD_Table", "TableName", "AD_ImpFormat")); - } - else{ - record_log (0, m_ImpFormat.getName(),"ImpFormat", m_ImpFormat.get_ID(),AD_Backup_ID, Object_Status,"AD_ImpFormat",get_IDWithColumn("AD_Table", "TableName", "AD_ImpFormat")); - } - } - //impformatrow element - else if (elementValue.equals("impformatrow")) { - log.info(elementValue+" "+atts.getValue("Name")); - - int impformid = get_ID("AD_ImpFormat", atts.getValue("ADImpFormatNameID")); - int tableid = get_IDWithColumn("AD_Table", "TableName", atts.getValue("ADTableNameID")); - int columnid = get_IDWithMasterAndColumn ("AD_Column","ColumnName", atts.getValue("ADColumnNameID"), "AD_Table", tableid); - sqlB = new StringBuffer ("SELECT AD_ImpFormat_Row_ID FROM AD_ImpFormat_Row WHERE AD_Column_ID=? and AD_ImpFormat_ID=?"); - int id = DB.getSQLValue(m_trxName,sqlB.toString(),columnid,impformid); - m_ImpFormat_row = new X_AD_ImpFormat_Row(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_ImpFormat",m_ImpFormat_row); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_ImpFormat_row.setName(atts.getValue("Name")); - m_ImpFormat_row.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_ImpFormat_row.setAD_Column_ID(columnid); - m_ImpFormat_row.setAD_ImpFormat_ID(impformid); - m_ImpFormat_row.setDataFormat(atts.getValue("DataFormat")); - m_ImpFormat_row.setDataType(atts.getValue("DataType")); - m_ImpFormat_row.setDecimalPoint(atts.getValue("DecimalPoint")); - m_ImpFormat_row.setDivideBy100(atts.getValue("isDivideBy100") != null ? Boolean.valueOf(atts.getValue("isDivideBy100")).booleanValue():true); - m_ImpFormat_row.setConstantValue(atts.getValue("ConstantValue")); - m_ImpFormat_row.setCallout(atts.getValue("Callout")); - m_ImpFormat_row.setEndNo(Integer.parseInt(atts.getValue("EndNo"))); - m_ImpFormat_row.setScript(atts.getValue("Script")); - m_ImpFormat_row.setSeqNo(Integer.parseInt(atts.getValue("SeqNo"))); - m_ImpFormat_row.setStartNo(Integer.parseInt(atts.getValue("StartNo"))); - if (m_ImpFormat_row.save(m_trxName) == true){ - record_log (1, m_ImpFormat_row.getName(),"ImpFormat", m_ImpFormat_row.get_ID(),AD_Backup_ID, Object_Status,"AD_ImpFormat",get_IDWithColumn("AD_Table", "TableName", "m_ImpFormat_row")); - } - else{ - record_log (0, m_ImpFormat_row.getName(),"ImpFormat", m_ImpFormat_row.get_ID(),AD_Backup_ID, Object_Status,"AD_ImpFormat",get_IDWithColumn("AD_Table", "TableName", "m_ImpFormat_row")); - } - } - - - // workbench element. - else if (elementValue.equals("workbench")) { - log.info(elementValue+" "+atts.getValue("ADWorkbenchNameID")); - String entitytype = atts.getValue("EntityType"); - String name = atts.getValue("ADWorkbenchNameID"); - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0 ) { - int id = get_ID("AD_Workbench", name); - m_Workbench = new X_AD_Workbench(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Workbench",m_Workbench); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - - int tableid = get_IDWithColumn("AD_Table", "TableName", atts.getValue("ADTableNameID")); - int columnid = get_IDWithMasterAndColumn ("AD_Column","ColumnName", atts.getValue("ADColumnNameID"), "AD_Table", tableid); - m_Workbench.setAD_Column_ID(columnid); - m_Workbench.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Workbench.setEntityType(atts.getValue("EntityType")); - m_Workbench.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); - m_Workbench.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Workbench.setName(atts.getValue("Name")); - //m_Workbench.setPA_Goal_ID(Integer.parseInt(atts.getValue("PAGoalID"))); - if (m_Workbench.save(m_trxName) == true){ - record_log (1, m_Workbench.getName(),"Workbench", m_Workbench.get_ID(),AD_Backup_ID, Object_Status,"AD_Workbench",get_IDWithColumn("AD_Table", "TableName", "AD_Workbench")); - } - else{ - record_log (0, m_Workbench.getName(),"Workbench", m_Workbench.get_ID(),AD_Backup_ID, Object_Status,"AD_Workbench",get_IDWithColumn("AD_Table", "TableName", "AD_Workbench")); - } - } - } - -// Snipit element. - else if (elementValue.equals("codesnipit")) { - log.info(elementValue); - Object_Status = "Update"; - String releaseNumber = atts.getValue("ReleaseNo"); - //Check Release Number - if(Adempiere.MAIN_VERSION.equals(releaseNumber)||releaseNumber.equals("all")){ - String sourceName = atts.getValue("filename"); - String targetDirectory = atts.getValue("filedir"); - String oldCode = atts.getValue("oldcode"); - String newCode = atts.getValue("newcode"); - - int idDetail=0; - InputStream source; // Stream for reading from the source file. - OutputStream copy; // Stream for writing the copy. - File currentDirectory = new File("."); - - String packagePath=null; - String sourcePath=null; - - //get compiere-all directory - try { - packagePath = currentDirectory.getCanonicalPath(); - File parentDirectory = new File(packagePath); - - while (!parentDirectory.getName().equals("packages")){ - parentDirectory = parentDirectory.getParentFile(); - } - parentDirectory = parentDirectory.getParentFile(); - sourcePath = parentDirectory.getCanonicalPath(); - } catch (IOException e1) { - System.out.println("Can't find compiere-all directory."); - } - - - // Create backup directory if required - File backupDir = new File(packagePath+fileSeperator+"backup"+fileSeperator); - if (!backupDir.exists()){ - boolean success = (new File(packagePath+fileSeperator+"backup"+fileSeperator)).mkdirs(); - if (!success) { - log.info("Backup directory creation failed"); - } - } - - //Correct target directory for proper file seperator - String fullDirectory = sourcePath+targetDirectory; - String targetDirectoryModified=null; - char slash1 = '\\'; - char slash2 = '/'; - if (fileSeperator.equals("/")) - targetDirectoryModified = fullDirectory.replace(slash1,slash2); - else - targetDirectoryModified = fullDirectory.replace(slash2,slash1); - - File file = new File(targetDirectoryModified+sourceName); - log.info(targetDirectoryModified+sourceName); - // check to see if overwrites are allowed - if (file.exists() && force == false) { - System.out.println( - "Output file exists. Use the -f option to replace it."); - return; - } - //backup file to package directory - else if (file.exists() && force == true) { - Object_Status = "Update"; - log.info("Target Backup:"+targetDirectoryModified+sourceName); - source = OpenInputfile(targetDirectoryModified+sourceName); - SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssSSSSZ"); - Date today = new Date(); - fileDate = formatter_file.format(today); - copy = OpenOutputfile(packagePath+fileSeperator+"backup"+fileSeperator+fileDate+"_"+sourceName); - log.info("Source Backup:"+packagePath+fileSeperator+"backup"+fileSeperator+fileDate+"_"+sourceName); - copyFile (source,copy); - log.info("Backup Complete"); - } - - int success = readReplace(targetDirectoryModified+sourceName, oldCode, newCode); - -// Record in log - int idBackup = MSequence.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Backup", m_trxName); - if (success != -1){ - try { - idDetail = record_log (1, sourceName,"codesnipit", 0,0, Object_Status,sourceName,0); - } catch (SAXException e) { - log.info ("setfile:"+e); - } - } - else{ - try { - idDetail = record_log (0, sourceName,"codesnipit", 0,0, Object_Status,sourceName,0); - } catch (SAXException e) { - log.info ("setfile:"+e); - } - } - //Record in transaction file - sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Backup" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," - + " AD_PACKAGE_IMP_ORG_DIR, AD_PACKAGE_IMP_BCK_DIR)" - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + idBackup - + ", " + idDetail - + ", " + AD_Package_Imp_ID - + ", '" + targetDirectoryModified+sourceName - + "', '" + packagePath+fileSeperator+"backup"+fileSeperator+fileDate+"_"+sourceName - +"')"); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to import backup failed"); - - } - } - - -// Copy Code to destination - else if (elementValue.equals("distfile")) { - log.info(elementValue+" "+atts.getValue("name")); - - String releaseNumber = atts.getValue("ReleaseNo"); - //log.info(atts.getValue("ReleaseNo")); - //log.info(Compiere.MAIN_VERSION); - //Check Release Number - if(releaseNumber==null||Adempiere.MAIN_VERSION.equals(releaseNumber)||releaseNumber.equals("all")){ - String sourceName = atts.getValue("name"); - String sourceDirectory = atts.getValue("sourceDirectory"); - String targetDirectory = atts.getValue("targetDirectory"); - - Object_Status = "New"; - int idDetail=0; - InputStream source; // Stream for reading from the source file. - OutputStream copy; // Stream for writing the copy. - - String packagePath=null; - String sourcePath=null; - - //get compiere-all directory - try { - packagePath = packageDirectory; - File parentDirectory = new File(packagePath); - while (!parentDirectory.getName().equals("packages")){ - parentDirectory = parentDirectory.getParentFile(); - } - parentDirectory = parentDirectory.getParentFile(); - sourcePath = parentDirectory.getCanonicalPath(); - } catch (IOException e1) { - System.out.println("Can't find compiere-all directory."); - } - - - // Create backup directory if required - File backupDir = new File(packagePath+fileSeperator+"backup"+fileSeperator); - if (!backupDir.exists()){ - boolean success = (new File(packagePath+fileSeperator+"backup"+fileSeperator)).mkdirs(); - if (!success) { - log.info("Backup directory creation failed"); - } - } - - - //Correct target directory for proper file seperator - String fullDirectory = sourcePath+targetDirectory; - String targetDirectoryModified=null; - char slash1 = '\\'; - char slash2 = '/'; - if (fileSeperator.equals("/")) - targetDirectoryModified = fullDirectory.replace(slash1,slash2); - else - targetDirectoryModified = fullDirectory.replace(slash2,slash1); - - File file = new File(targetDirectoryModified+sourceName); - //check to see if overwrites are allowed - if (file.exists() && force == false) { - System.out.println( - "Output file exists. Use the -f option to replace it."); - return; - } - //backup file to package directory - else if (file.exists() && force == true) { - Object_Status = "Update"; - log.info("Target Backup:"+targetDirectoryModified+sourceName); - source = OpenInputfile(targetDirectoryModified+sourceName); - SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssSSSSZ"); - Date today = new Date(); - fileDate = formatter_file.format(today); - copy = OpenOutputfile(packagePath+fileSeperator+"backup"+fileSeperator+fileDate+"_"+sourceName); - log.info("Source Backup:"+packagePath+fileSeperator+"backup"+fileSeperator+fileDate+"_"+sourceName); - copyFile (source,copy); - log.info("Backup Complete"); - } - -// Correct dist directory for proper file seperator - String distDirectoryModified=null; - if (fileSeperator.equals("/")) - distDirectoryModified = sourceDirectory.replace(slash1,slash2); - else - distDirectoryModified = sourceDirectory.replace(slash2,slash1); - source = OpenInputfile(packagePath+distDirectoryModified+sourceName); - -// Create Target directory if required - File targetDir = new File(targetDirectoryModified); - if (!targetDir.exists()){ - boolean success = (new File(targetDirectoryModified)).mkdirs(); - if (!success) { - log.info("Target directory creation failed"); - } - } - copy = OpenOutputfile(targetDirectoryModified+sourceName); - //Copy File - int success = copyFile (source,copy); - //Record in log - int idBackup = MSequence.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Backup", m_trxName); - if (success != -1){ - try { - idDetail = record_log (1, sourceName,"file", 0,0, Object_Status,sourceName,0); - } catch (SAXException e) { - log.info ("setfile:"+e); - } - } - else{ - try { - idDetail = record_log (0, sourceName,"file", 0,0, Object_Status,sourceName,0); - } catch (SAXException e) { - log.info ("setfile:"+e); - } - } - //Record in transaction file - sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Backup" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," - + " AD_PACKAGE_IMP_ORG_DIR, AD_PACKAGE_IMP_BCK_DIR)" - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + idBackup - + ", " + idDetail - + ", " + AD_Package_Imp_ID - + ", '" + targetDirectoryModified+sourceName - + "', '" + packagePath+fileSeperator+"backup"+fileSeperator+fileDate+"_"+sourceName - +"')"); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to import backup failed"); - - } - } - // workbenchwindow element - else if (elementValue.equals("workbenchwindow")) { -// TODO: Solve for lack of name to identify window - log.info(elementValue+" not supported yet"); - } - else if (elementValue.equals("reportview")) { - log.info(elementValue+" "+atts.getValue("ADReportviewnameID")); - String entitytype = atts.getValue("EntityType"); - String name = atts.getValue("ADReportviewnameID"); - - int id = get_ID("AD_ReportView", name); - m_Reportview = new X_AD_ReportView(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Reportview",m_Reportview); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - String Name = atts.getValue("ADTableNameID"); - id = get_IDWithColumn("AD_Table", "TableName", Name); - if (id == 0 ){ - m_Table = new MTable(m_ctx, 0, m_trxName); - m_Table.setAccessLevel("3"); - m_Table.setName(Name); - m_Table.setTableName(Name); - if (m_Table.save(m_trxName) == true){ - record_log (1, m_Table.getName(),"Table", m_Table.get_ID(),0, "New","AD_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Table")); - } - else{ - record_log (0, m_Table.getName(),"Table", m_Table.get_ID(),0, "New","AD_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Table")); - } - id = get_IDWithColumn("AD_Table", "TableName", Name); - } - - m_Reportview.setAD_Table_ID(id); - m_Reportview.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Reportview.setEntityType(atts.getValue("EntityType")); - m_Reportview.setName(atts.getValue("Name")); - m_Reportview.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Reportview.setOrderByClause(atts.getValue("OrderByClause")); - m_Reportview.setWhereClause(atts.getValue("WhereClause")); - if (m_Reportview.save(m_trxName) == true){ - record_log (1, m_Reportview.getName(),"Reportview", m_Reportview.get_ID(),AD_Backup_ID, Object_Status,"AD_Reportview",get_IDWithColumn("AD_Table", "TableName", "AD_Reportview")); - } - else{ - record_log (0, m_Reportview.getName(),"Reportview", m_Reportview.get_ID(),AD_Backup_ID, Object_Status,"AD_Reportview",get_IDWithColumn("AD_Table", "TableName", "AD_Reportview")); - } - - } - - else if (elementValue.equals("printformat")) { - log.info(elementValue+" "+atts.getValue("Name")); - - String name = atts.getValue("Name"); - int id = get_IDWithColumn("AD_PrintFormat", "Name", name); - m_PrintFormat = new X_AD_PrintFormat(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_PrintFormat",m_PrintFormat); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - - name = atts.getValue("ADReportviewnameID"); - id = get_IDWithColumn("AD_ReportView", "Name", name); - m_PrintFormat.setAD_ReportView_ID(id); - name = atts.getValue("ADTableNameID"); - id = get_IDWithColumn("AD_Table", "TableName", name); - if (id == 0 ){ - m_Table = new MTable(m_ctx, 0, m_trxName); - m_Table.setAccessLevel("3"); - m_Table.setName(name); - m_Table.setTableName(name); - if (m_Table.save(m_trxName) == true){ - record_log (1, m_Table.getName(),"Table", m_Table.get_ID(),0, "New","AD_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Table")); - } - else{ - record_log (0, m_Table.getName(),"Table", m_Table.get_ID(),0, "New","AD_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Table")); - } - id = get_IDWithColumn("AD_Table", "TableName", name); - } - m_PrintFormat.setAD_Table_ID(id); - - name = atts.getValue("ADPrintTableFormatID"); - id = get_IDWithColumn("AD_PrintTableFormat", "Name", name); - m_PrintFormat.setAD_PrintTableFormat_ID(id); - name = atts.getValue("ADPrintColorID"); - id = get_IDWithColumn("AD_PrintColor", "Name", name); - - m_PrintFormat.setAD_PrintColor_ID(id); - name = atts.getValue("ADPrintFontID"); - id = get_IDWithColumn("AD_PrintFont", "Name", name); - m_PrintFormat.setAD_PrintFont_ID(id); - - name = atts.getValue("ADPrintPaperID"); - id = get_IDWithColumn("AD_PrintPaper", "Name", name); - m_PrintFormat.setAD_PrintPaper_ID(id); - - m_PrintFormat.setDescription (atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_PrintFormat.setName (atts.getValue("Name")); - m_PrintFormat.setPrinterName(atts.getValue("PrinterName")); - m_PrintFormat.setFooterMargin(Integer.parseInt(atts.getValue("FooterMargin"))); - - m_PrintFormat.setHeaderMargin(Integer.parseInt(atts.getValue("HeaderMargin"))); - m_PrintFormat.setCreateCopy(atts.getValue("CreateCopy")); - m_PrintFormat.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - - m_PrintFormat.setIsTableBased(Boolean.valueOf(atts.getValue("isTableBased")).booleanValue()); - m_PrintFormat.setIsForm(Boolean.valueOf(atts.getValue("isForm")).booleanValue()); - m_PrintFormat.setIsStandardHeaderFooter(Boolean.valueOf(atts.getValue("isStandardHeader")).booleanValue()); - - m_PrintFormat.setIsDefault(Boolean.valueOf(atts.getValue("isDefault")).booleanValue()); - if (m_PrintFormat.save(m_trxName) == true){ - record_log (1, m_PrintFormat.getName(),"PrintFormat", m_PrintFormat.get_ID(),AD_Backup_ID, Object_Status,"AD_PrintFormat",get_IDWithColumn("AD_Table", "TableName", "AD_PrintFormat")); - } - else{ - record_log (0, m_PrintFormat.getName(),"PrintFormat", m_PrintFormat.get_ID(),AD_Backup_ID, Object_Status,"AD_PrintFormat",get_IDWithColumn("AD_Table", "TableName", "AD_PrintFormat")); - } - } - - - else if (elementValue.equals("printformatitem")) { - log.info(elementValue+" "+atts.getValue("Name")); - - String name = atts.getValue("Name"); - int id = get_IDWithMaster("AD_PrintFormatItem", name,"AD_PrintFormat",atts.getValue("ADPrintFormatNameID")); - - m_PrintFormatItem = new X_AD_PrintFormatItem(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_PrintFormatItem",m_PrintFormatItem); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - m_PrintFormatItem.setName(name); - name = atts.getValue("ADPrintFormatNameID"); - id = get_IDWithColumn("AD_PrintFormat", "Name", name); - m_PrintFormatItem.setAD_PrintFormat_ID(id); - //name = atts.getValue("ADPrintFormatChildNameID"); - //id = get_IDWithColumn("AD_PrintFormat", "Name", name); - //m_PrintFormatItem.setAD_PrintFormatChild_ID(id); - name = atts.getValue("ADTableNameID"); - int tableid = get_IDWithColumn("AD_Table", "TableName", name); - name = atts.getValue("ADColumnNameID"); - id =get_IDWithMasterAndColumn ("AD_Column", "ColumnName", name, "AD_Table", tableid); - if(id > 0) - m_PrintFormatItem.setAD_Column_ID(id); - name = atts.getValue("ADPrintGraphID"); - id = get_IDWithColumn("AD_PrintGraph", "Name", name); - m_PrintFormatItem.setAD_PrintGraph_ID(id); - name = atts.getValue("ADPrintColorID"); - id = get_IDWithColumn("AD_PrintColor", "Name", name); - m_PrintFormatItem.setAD_PrintColor_ID(id); - name = atts.getValue("ADPrintFontID"); - id = get_IDWithColumn("AD_PrintFont", "Name", name); - m_PrintFormatItem.setAD_PrintFont_ID(id); - - m_PrintFormatItem.setPrintName(atts.getValue("PrintName")); - m_PrintFormatItem.setName(atts.getValue("Name")); - m_PrintFormatItem.setPrintAreaType(atts.getValue("PrintAreaType")); - - m_PrintFormatItem.setSeqNo(Integer.parseInt(atts.getValue("SeqNo"))); - m_PrintFormatItem.setPrintFormatType(atts.getValue("PrintFormatType")); - m_PrintFormatItem.setXSpace(Integer.parseInt(atts.getValue("XSpace"))); - - m_PrintFormatItem.setYSpace(Integer.parseInt(atts.getValue("YSpace"))); - m_PrintFormatItem.setXPosition(Integer.parseInt(atts.getValue("Xposition"))); - m_PrintFormatItem.setYPosition(Integer.parseInt(atts.getValue("Yposition"))); - - m_PrintFormatItem.setMaxWidth(Integer.parseInt(atts.getValue("MaxWidth"))); - m_PrintFormatItem.setMaxHeight(Integer.parseInt(atts.getValue("MaxHieght"))); - m_PrintFormatItem.setSortNo(Integer.parseInt(atts.getValue("SortNo"))); - - m_PrintFormatItem.setFieldAlignmentType(atts.getValue("FieldAlignmentType")); - m_PrintFormatItem.setLineAlignmentType(atts.getValue("LineAlignmentType")); - m_PrintFormatItem.setImageURL(atts.getValue("ImageURL")); - m_PrintFormatItem.setArcDiameter(Integer.parseInt(atts.getValue("ArcDiameter"))); - m_PrintFormatItem.setLineWidth(Integer.parseInt(atts.getValue("LineWidth"))); - m_PrintFormatItem.setShapeType(atts.getValue("ShapeType")); - - m_PrintFormatItem.setBelowColumn(Integer.parseInt(atts.getValue("BelowColumn"))); - m_PrintFormatItem.setPrintNameSuffix(atts.getValue("PrintNameSuffix")); - m_PrintFormatItem.setRunningTotalLines(Integer.parseInt(atts.getValue("RunningTotalLines"))); - - m_PrintFormatItem.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_PrintFormatItem.setIsPrinted(Boolean.valueOf(atts.getValue("isPrinted")).booleanValue()); - m_PrintFormatItem.setIsRelativePosition(Boolean.valueOf(atts.getValue("isRelativePosition")).booleanValue()); - m_PrintFormatItem.setIsNextLine(Boolean.valueOf(atts.getValue("isNextLine")).booleanValue()); - - m_PrintFormatItem.setIsHeightOneLine(Boolean.valueOf(atts.getValue("isHeightOneLine")).booleanValue()); - m_PrintFormatItem.setIsOrderBy(Boolean.valueOf(atts.getValue("isOrderBy")).booleanValue()); - m_PrintFormatItem.setIsGroupBy(Boolean.valueOf(atts.getValue("isGroupBy")).booleanValue()); - - m_PrintFormatItem.setIsPageBreak(Boolean.valueOf(atts.getValue("isPageBreak")).booleanValue()); - m_PrintFormatItem.setIsSummarized(Boolean.valueOf(atts.getValue("isSummarized")).booleanValue()); - m_PrintFormatItem.setImageIsAttached(Boolean.valueOf(atts.getValue("isImageIsAttached")).booleanValue()); - - m_PrintFormatItem.setIsAveraged(Boolean.valueOf(atts.getValue("isAveraged")).booleanValue()); - m_PrintFormatItem.setIsCounted(Boolean.valueOf(atts.getValue("isCounted")).booleanValue()); - m_PrintFormatItem.setIsSetNLPosition(Boolean.valueOf(atts.getValue("isSetNLPosition")).booleanValue()); - m_PrintFormatItem.setIsSuppressNull(Boolean.valueOf(atts.getValue("isSuppressNull")).booleanValue()); - - m_PrintFormatItem.setIsFixedWidth(Boolean.valueOf(atts.getValue("isFixedWidth")).booleanValue()); - m_PrintFormatItem.setIsNextPage(Boolean.valueOf(atts.getValue("isNextPage")).booleanValue()); - m_PrintFormatItem.setIsMaxCalc(Boolean.valueOf(atts.getValue("isMaxCalc")).booleanValue()); - m_PrintFormatItem.setIsMinCalc(Boolean.valueOf(atts.getValue("isMinCalc")).booleanValue()); - - m_PrintFormatItem.setIsRunningTotal(Boolean.valueOf(atts.getValue("isRunningTotal")).booleanValue()); - m_PrintFormatItem.setIsVarianceCalc(Boolean.valueOf(atts.getValue("isVarianceCalc")).booleanValue()); - m_PrintFormatItem.setIsDeviationCalc(Boolean.valueOf(atts.getValue("isDeviationCalc")).booleanValue()); - - if (m_PrintFormatItem.save(m_trxName) == true){ - record_log (1, m_PrintFormatItem.getName(),"PrintFormatItem", m_PrintFormatItem.get_ID(),AD_Backup_ID, Object_Status,"AD_PrintFormatItem",get_IDWithColumn("AD_Table", "TableName", "AD_PrintFormatItem")); - } - else{ - record_log (0, m_PrintFormatItem.getName(),"PrintFormatItem", m_PrintFormatItem.get_ID(),AD_Backup_ID, Object_Status,"AD_PrintFormatItem",get_IDWithColumn("AD_Table", "TableName", "AD_PrintFormatItem")); - } - } - else if (elementValue.equals("reportviewcol")) { - log.info(elementValue+" "+atts.getValue("ADReportViewColID")); - - String entitytype = atts.getValue("EntityType"); - String name = atts.getValue("ADReportViewColID"); - - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0 ) { - int id = get_ID("AD_Reportview_Col", name); - m_Reportview_Col = new X_AD_ReportView_Col(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Reportview_Col",m_Reportview_Col); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - name = atts.getValue("ADReportviewnameID"); - id = get_IDWithColumn("AD_Reference", "Name", name); - m_Reportview_Col.setAD_ReportView_ID(id); - name = atts.getValue("ADColumnNameID"); - id = get_IDWithColumn("AD_Column", "Name", name); - m_Reportview_Col.setAD_Column_ID(id); - m_Reportview_Col.setFunctionColumn(atts.getValue("ADColumnNameID")); - m_Reportview_Col.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Reportview_Col.setIsGroupFunction(Boolean.valueOf(atts.getValue("ADColumnNameID")).booleanValue()); - if (m_Reportview_Col.save(m_trxName) == true){ - record_log (1, ""+m_Reportview_Col.getAD_ReportView_ID(),"Reportview_Col", m_Reportview.get_ID(),AD_Backup_ID, Object_Status,"AD_Reportview_Col",get_IDWithColumn("AD_Table", "TableName", "AD_Reportview_Col")); - } - else{ - record_log (0, ""+m_Reportview_Col.getAD_ReportView_ID(),"Reportview_Col", m_Reportview.get_ID(),AD_Backup_ID, Object_Status,"AD_Reportview_Col",get_IDWithColumn("AD_Table", "TableName", "AD_Reportview_Col")); - } - } - } - else if (elementValue.equals("SQLStatement")) { - log.info(elementValue); - - String DBType = atts.getValue("DBType"); - PreparedStatement pstmt = DB.prepareStatement(atts.getValue("statement"), m_trxName); - try { - if(DBType.equals("ALL")) { - int n = pstmt.executeUpdate(); - log.info("Executed SQL Statement: "+ atts.getValue("statement")); - } - else if(DB.isOracle() == true && DBType.equals("Oracle")) { - pstmt.executeUpdate(); - log.info("Executed SQL Statement for Oracle: "+ atts.getValue("statement")); - } - else if(DB.isPostgreSQL() == true && DBType.equals("PostgreSQL")){ - // Avoid convert layer - command specific for postgresql - // - // pstmt = DB.prepareStatement(sql, null); - // pstmt.executeUpdate(); - // - Connection m_con = DB.getConnectionRW(true); - Statement stmt = m_con.createStatement(); - int n = stmt.executeUpdate (atts.getValue("statement")); - log.info("Executed SQL Statement for PostgreSQL: "+ atts.getValue("statement")); - // Postgres needs to commit DDL statements - if (m_con != null && !m_con.getAutoCommit()) - m_con.commit(); - } - /* else if(DB.isSybase() == true && DBType.equals("Sybase")){ - pstmt.executeUpdate(); - log.info("Exceuted SQL Statement for Sybase"); - } - */ } - catch (Exception e) { - log.log(Level.SEVERE,"SQLSatement", e); - } - } - else if (elementValue.equals("reference")) { - log.info(elementValue+" "+atts.getValue("name")); - - String entitytype = atts.getValue("EntityType"); - String name = atts.getValue("name"); - - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0 ) { - int id = get_ID("AD_Reference", name); - - m_Reference = new X_AD_Reference(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Reference",m_Reference); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - - m_Reference.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Reference.setEntityType(atts.getValue("EntityType")); - m_Reference.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); - m_Reference.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Reference.setName(atts.getValue("name")); - - //m_Reference.setVFormat(atts.getValue("VFormat")); - m_Reference.setValidationType(atts.getValue("ValidationType")); - if (m_Reference.save(m_trxName) == true){ - record_log (1, m_Reference.getName(),"Reference", m_Reference.get_ID(),AD_Backup_ID, Object_Status,"AD_Reference",get_IDWithColumn("AD_Table", "TableName", "AD_Reference")); - } - else{ - record_log (0, m_Reference.getName(),"Reference", m_Reference.get_ID(),AD_Backup_ID, Object_Status,"AD_Reference",get_IDWithColumn("AD_Table", "TableName", "AD_Reference")); - } - - } - } - else if (elementValue.equals("referencelist")) { - log.info(elementValue+" "+atts.getValue("Name")); - //TODO: Solve for date issues with valuefrom valueto - String entitytype = atts.getValue("EntityType"); - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0 ) { - String name = atts.getValue("Name"); - int Referenceid = get_IDWithColumn("AD_Reference", "Name", atts.getValue("ADRefenceNameID")); - int id = get_IDWithMaster("AD_Ref_List", name, "AD_Reference",Referenceid); - m_Ref_List = new X_AD_Ref_List(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord("AD_Ref_List",m_Ref_List); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - name = atts.getValue("ADRefenceNameID"); - id = get_IDWithColumn("AD_Reference", "Name", name); - m_Ref_List.setAD_Reference_ID(id); - m_Ref_List.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); - m_Ref_List.setEntityType (atts.getValue("EntityType")); - m_Ref_List.setName(atts.getValue("Name")); - m_Ref_List.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); - m_Ref_List.setValue(atts.getValue("Value")); - if (m_Ref_List.save(m_trxName) == true){ - record_log (1, m_Ref_List.getName(),"Reference List", m_Ref_List.get_ID(),AD_Backup_ID, Object_Status,"AD_Ref_List",get_IDWithColumn("AD_Table", "TableName", "AD_Ref_List")); - } - else{ - record_log (0, m_Ref_List.getName(),"Reference List", m_Ref_List.get_ID(),AD_Backup_ID, Object_Status,"AD_Ref_List",get_IDWithColumn("AD_Table", "TableName", "AD_Ref_List")); - } - } - } - else if (elementValue.equals("referencetable")) { - log.info(elementValue); - - String entitytype = atts.getValue("EntityType"); - String name = atts.getValue("ADRefenceNameID"); - if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && m_UpdateMode.compareTo("true") == 0 ) { - sqlB = new StringBuffer ("SELECT AD_Reference_ID FROM AD_Reference WHERE Name= ?"); - int id = DB.getSQLValue(m_trxName,sqlB.toString(),name); - sqlB = new StringBuffer ("SELECT Count(*) FROM AD_Ref_Table WHERE AD_Reference_ID= ?"); - int count = DB.getSQLValue(m_trxName, sqlB.toString(),id); - int tableId = get_IDWithColumn("AD_Table", "TableName", atts.getValue("ADTableNameID")); - if (tableId ==0){ - m_Table = new MTable(m_ctx, 0, m_trxName); - m_Table.setAccessLevel("3"); - m_Table.setName(atts.getValue("ADTableNameID")); - m_Table.setTableName(atts.getValue("ADTableNameID")); - if (m_Table.save(m_trxName) == true){ - record_log (1, m_Table.getName(),"Table", m_Table.get_ID(),0, "New","AD_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Table")); - } - else{ - record_log (0, m_Table.getName(),"Table", m_Table.get_ID(),0, "New","AD_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Table")); - } - tableId = get_IDWithColumn("AD_Table", "TableName", atts.getValue("ADTableNameID")); - } - name = atts.getValue("ADDisplay"); - int DisplayId =get_IDWithMasterAndColumn ("AD_Column", "ColumnName", name, "AD_Table", tableId); - if (DisplayId ==0){ - m_Column = new MColumn(m_ctx,0,m_trxName); - m_Column.setAD_Table_ID(tableId); - // m_Column.setVersion(new BigDecimal("1")); // use constructor value - m_Column.setColumnName(name); - m_Column.setName(name); - m_Column.setAD_Reference_ID(30); - if (m_Column.save(m_trxName) == true){ - record_log (1, m_Column.getName(),"Column", m_Column.get_ID(),0, "New","AD_Column",get_IDWithColumn("AD_Table", "TableName", "AD_Column")); - } - else{ - record_log (0, m_Column.getName(),"Column", m_Column.get_ID(),0, "New","AD_Column",get_IDWithColumn("AD_Table", "TableName", "AD_Column")); - } - } - name = atts.getValue("Key"); - int keyId =get_IDWithMasterAndColumn ("AD_Column", "ColumnName", name, "AD_Table", tableId); - if (keyId ==0){ - m_Column = new MColumn(m_ctx,0,m_trxName); - m_Column.setAD_Table_ID(tableId); - //m_Column.setVersion(new BigDecimal("1")); // use constructor value - m_Column.setColumnName(name); - m_Column.setName(name); - m_Column.setAD_Reference_ID(30); - if (m_Column.save(m_trxName) == true){ - record_log (1, m_Column.getName(),"Column", m_Column.get_ID(),0, "New","AD_Column",get_IDWithColumn("AD_Table", "TableName", "AD_Column")); - } - else{ - record_log (0, m_Column.getName(),"Column", m_Column.get_ID(),0, "New","AD_Column",get_IDWithColumn("AD_Table", "TableName", "AD_Column")); - } - } - - name = atts.getValue("ADDisplay"); - DisplayId = get_IDWithMasterAndColumn ("AD_Column", "ColumnName", name, "AD_Table", tableId); - name = atts.getValue("Key"); - keyId = get_IDWithMasterAndColumn ("AD_Column", "ColumnName", name, "AD_Table", tableId); - String entityType = atts.getValue("EntityType"); - String isValueDisplayed = atts.getValue("IsValueDisplayed"); - String OrderByClause= atts.getValue("OrderByClause").replaceAll("'","''").replaceAll(",",""); - String WhereClause= atts.getValue("WhereClause").replaceAll("'","''").replaceAll(",",""); - if (count >0 ){ - sqlB = new StringBuffer ("UPDATE AD_Ref_Table " - + "SET AD_Table_ID = " + tableId - + ", AD_Display = " + DisplayId - + ", AD_Key = " + keyId - + ", isValueDisplayed = '" + isValueDisplayed - + "', OrderByClause = '" + OrderByClause - + "', EntityType ='" + entityType - + "', WhereClause = '" + WhereClause - + "' WHERE AD_Reference_ID = " + id); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no > 0){ - record_log (1, atts.getValue("ADRefenceNameID"),"Reference Table", id,0, "Update","AD_Ref_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Ref_Table")); - } - else{ - record_log (0, atts.getValue("ADRefenceNameID"),"Reference Table", id,0, "Update","AD_Ref_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Ref_Table")); - } - - } - else{ - sqlB = new StringBuffer ("Insert INTO AD_Ref_Table" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_Reference_ID, AD_Table_ID, AD_Display, AD_Key " - + ",entityType, isValueDisplayed, OrderByClause, " - + " WhereClause )" - + "VALUES(0, 0, 0, 0, "+id - + ", " + tableId - + ", " + DisplayId - + ", " + keyId - + ", '" + entityType - + "', '" + isValueDisplayed - + "', '" + OrderByClause - + "', '" + WhereClause +"')"); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no > 0){ - record_log (1, atts.getValue("ADRefenceNameID"),"Reference Table", id,0, "New","AD_Ref_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Ref_Table")); - } - else{ - record_log (0, atts.getValue("ADRefenceNameID"),"Reference Table", id,0, "New","AD_Ref_Table",get_IDWithColumn("AD_Table", "TableName", "AD_Ref_Table")); - } - } - } - } - else if (elementValue.equals("menuset")) { - log.info(elementValue); - setmenu (); - } - - /* **************************************** - adempieredata Handler. - **************************************** */ - // table element, adempieredata - else if (elementValue.equals("dtable")) { - log.info(elementValue+" "+atts.getValue("name")); - d_tablename = atts.getValue("name"); - } - // row element, adempieredata - else if (elementValue.equals("drow")) { - log.info(elementValue+" "+atts.getValue("name")); - d_rowname = atts.getValue("name"); - Properties ctx = m_ctx; - ctx.setProperty("adempieredataTable_ID", String.valueOf(get_IDWithColumn("AD_Table", "TableName", d_tablename))); - // name can be null if there are keyXname attributes. - if (!d_rowname.equals("")){ - int id = get_ID(d_tablename, d_rowname); - genericPO = new GenericPO(m_ctx, id, m_trxName); - if (id > 0){ - AD_Backup_ID = copyRecord(d_tablename,genericPO); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - } - // keyXname and lookupkeyXname. - else { - String sql = "select * from "+d_tablename; - String whereand = " where"; - String t_tablename = null; - String CURRENT_KEY = "key1name"; - if (!atts.getValue(CURRENT_KEY).equals("")) { - t_tablename = atts.getValue(CURRENT_KEY).substring(0, atts.getValue(CURRENT_KEY).length()-3); - sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY); - whereand = " and"; - } - CURRENT_KEY = "key2name"; - if (!atts.getValue(CURRENT_KEY).equals("")) { - t_tablename = atts.getValue(CURRENT_KEY).substring(0, atts.getValue(CURRENT_KEY).length()-3); - sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY); - whereand = " and"; - } - // Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value - try { - PreparedStatement pstmt = DB.prepareStatement(sql, m_trxName); - - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) { - Object_Status = "Update"; - genericPO = new GenericPO(m_ctx, rs, m_trxName); - rs.close(); - pstmt.close(); - pstmt = null; - } - else { - genericPO = new GenericPO(m_ctx, 0, m_trxName); - rs.close(); - pstmt.close(); - pstmt = null; - Object_Status = "New"; - // set keyXname. - CURRENT_KEY = "key1name"; - if (!atts.getValue(CURRENT_KEY).equals("")) { - t_tablename = atts.getValue(CURRENT_KEY).substring(0, atts.getValue(CURRENT_KEY).length()-3); - genericPO.setValueNoCheck(atts.getValue(CURRENT_KEY), atts.getValue("lookup"+CURRENT_KEY)); - } - CURRENT_KEY = "key2name"; - if (!atts.getValue(CURRENT_KEY).equals("")) { - t_tablename = atts.getValue(CURRENT_KEY).substring(0, atts.getValue(CURRENT_KEY).length()-3); - genericPO.setValueNoCheck(atts.getValue(CURRENT_KEY), atts.getValue("lookup"+CURRENT_KEY)); - } - } - - } - catch (Exception e) { - log.info ("keyXname attribute. init from rs error."+e); - } - } - // reset Table ID for GenericPO. - ctx.setProperty("adempieredataTable_ID", "0"); - // for debug GenericPO. - if (false) { - POInfo poInfo = POInfo.getPOInfo(m_ctx, get_ID("AD_Table", d_tablename)); - if (poInfo == null) - log.info("poInfo is null."); - for (int i = 0; i < poInfo.getColumnCount(); i++) { - log.info(d_tablename+" column: "+poInfo.getColumnName(i)); - } - } - // globalqss: set AD_Client_ID to the client setted in adempieredata - if (m_AD_Client_ID > 0 && genericPO.getAD_Client_ID() != m_AD_Client_ID) - genericPO.setValue("AD_Client_ID", m_AD_Client_ID); - // 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.setValue("Name", d_rowname); - // Set defaults. - 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.setValue((String)thisValue.get(0), (String)thisValue.get(1)); - else if (((String)(thisValue.get(2))).equals("Integer")) - genericPO.setValue((String)thisValue.get(0), Integer.valueOf((String)thisValue.get(1))); - else if (((String)(thisValue.get(2))).equals("Boolean")) - genericPO.setValue((String)thisValue.get(0), new Boolean(((String)thisValue.get(1)).equals("true") ? true : false)); - } - } - } - } - - // column element, adempieredata - else if (elementValue.equals("dcolumn")) { - log.info(elementValue+" "+atts.getValue("name")); - String columnName = atts.getValue("name"); - int tableid = get_IDWithColumn("AD_Table", "TableName", d_tablename); - int id =get_IDWithMasterAndColumn ("AD_Column", "ColumnName", columnName, "AD_Table", tableid); - StringBuffer sql = new StringBuffer ("SELECT IsUpdateable FROM AD_column WHERE AD_Column_ID = ?"); - String isUpdateable = DB.getSQLValueString(m_trxName, sql.toString(),id); - sql = new StringBuffer ("SELECT IsKey FROM AD_column WHERE AD_Column_ID = ?"); - String isKey = DB.getSQLValueString(m_trxName, sql.toString(),id); - if (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")) { - 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.setValue(atts.getValue("name").toString(), atts.getValue("value").toString()); - } - else if (atts.getValue("class").equals("Number") || atts.getValue("class").equals("Amount") - || atts.getValue("class").equals("Quantity")|| atts.getValue("class").equals("Costs+Prices")){ - genericPO.setValue(atts.getValue("name").toString(), new BigDecimal(atts.getValue("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.setValue(atts.getValue("name").toString(), Integer.valueOf(atts.getValue("value"))); - } - else if (atts.getValue("class").equals("Boolean")) { - genericPO.setValue(atts.getValue("name"), new Boolean(atts.getValue("value").equals("true") ? true : false)); - } - else if (atts.getValue("class").equals("Date") || atts.getValue("class").equals("Date+Time") - || atts.getValue("class").equals("Time")) { - genericPO.setValue(atts.getValue("name").toString(), Timestamp.valueOf(atts.getValue("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.setValue(atts.getValue("name"), new Integer(getIDbyName(m_tablename, atts.getValue("lookupname")))); - } - } - } + else { + Element e = new Element(uri, localName, qName, atts); + stack.push(e); + ElementHandler handler = handlers.get(elementValue); + if (handler != null) + handler.startElement(m_ctx, e); + if (e.defer) + defer.add(new DeferEntry(e, true)); } } // startElement /** - * Get ID from Name for a table. - * TODO: substitute with PO.getAllIDs - * - * @param tableName - * @param name - * - */ - public int get_ID (String tableName, String name) { - int id = 0; - sqlB = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where name=?"); - - if (!tableName.startsWith("AD_")) - sqlB = sqlB.append(" and AD_Client_ID=?"); - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), m_trxName); - pstmt.setString(1, name); - if (!tableName.startsWith("AD_")) - pstmt.setInt(2, m_AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) - id = rs.getInt(1); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("get_ID:"+e); - } - return id; - } - - /** - * Get ID from column value for a table. - * - * @param tableName - * @param columName - * @param name - */ - public int get_IDWithColumn (String tableName, String columnName, Object value) { - int id = 0; - sqlB = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where UPPER("+columnName+")=?"); - //StringBuffer sqlC = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where "+columnName+"="+value.toString()); - - if (!tableName.startsWith("AD_")) - sqlB = sqlB.append(" and AD_Client_ID=?"); - //here! - sqlB = sqlB.append(" Order By "+tableName+"_ID"); - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), m_trxName); - if (value instanceof String) - pstmt.setString(1, ((String)value).toUpperCase()); - else if (value instanceof Integer) - pstmt.setInt(1, ((Integer)value).intValue()); - if (!tableName.startsWith("AD_")) - pstmt.setInt(2, m_AD_Client_ID); - - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) - id = rs.getInt(1); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("get_ID:"+e); - } - 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 (String tableName, String name, String tableNameMaster, String nameMaster) { - int id = 0; - sqlB = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where UPPER(name)=? and " - + tableNameMaster+"_ID = (select "+tableNameMaster+"_ID from "+tableNameMaster+" where UPPER(name)=?)"); - - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), m_trxName); - pstmt.setString(1, name.toUpperCase()); - pstmt.setString(2, nameMaster.toUpperCase()); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) - id = rs.getInt(1); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("get_IDWithMaster:"+e); - } - return id; - } - - /** - * Get ID from Name for a table with a Master reference. - * - * @param tableName - * @param name - * @param tableNameMaster - * @param nameMaster - */ - - public int get_IDWithMasterAndColumn (String tableName, String columnName, String name, String tableNameMaster, int masterID) { - int id = 0; - sqlB = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where UPPER("+columnName+")=? and " - + tableNameMaster+"_ID =?"); - //StringBuffer sqlC = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where "+columnName+"="+name+" and " - // + tableNameMaster+"_ID ="+masterID); - log.info(sqlB.toString()); - - try { - - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), m_trxName); - pstmt.setString(1, name.toUpperCase()); - pstmt.setInt(2, masterID); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) - id = rs.getInt(1); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("get_IDWithMasterAndColumn:"+e); - } - return id; - } - - /** - * Get ID from Name for a table with a Master reference ID. - * - * @param tableName - * @param name - * @param tableNameMaster - * @param masterID - */ - public int get_IDWithMaster (String tableName, String name, String tableNameMaster, int masterID) { - int id = 0; - sqlB = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where name=? and " - + tableNameMaster+"_ID=?"); - - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), m_trxName); - pstmt.setString(1, name); - pstmt.setInt(2, masterID); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) - id = rs.getInt(1); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("get_IDWithMasterID:"+e); - } - return id; - } - - /** - * Get ID from Name for a table. - * TODO: substitute with PO.getAllIDs - * - * @param tableName - * @param name - */ - public int getIDbyName (String tableName, String name) { - int id = 0; - String sql = "SELECT "+tableName+"_ID " - + "FROM "+tableName+" " - + "WHERE name=?"; - if (!tableName.startsWith("AD_")) - sql = sql + " AND AD_Client_ID=?"; - try { - PreparedStatement pstmt = DB.prepareStatement(sql, m_trxName); - pstmt.setString(1, name); - if (!tableName.startsWith("AD_")) - pstmt.setInt(2, m_AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) - id = rs.getInt(1); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.log(Level.SEVERE, "getID:"+e); - } - return id; - } - - /** - * Set menu tree. - * - * - * - * - */ - public void setmenu () { - - String name = null; - int idDetail =0; - int i; - for(i=0;i 0){ - AD_Backup_ID = copyRecord("AD_Menu",m_Menu); - Object_Status = "Update"; - } - else{ - Object_Status = "New"; - AD_Backup_ID =0; - } - - m_Menu.setName(name); - name = d_menu[i][1]; - int id = get_IDWithColumn("AD_Window", "Name", name); - m_Menu.setAD_Window_ID(id); - name = d_menu[i][2]; - id = get_IDWithColumn("AD_Process", "Name", name); - m_Menu.setAD_Process_ID(id); - name = d_menu[i][3]; - id = get_IDWithColumn("AD_Form", "Name", name); - m_Menu.setAD_Form_ID(id); - name = d_menu[i][4]; - id = get_IDWithColumn("AD_Task", "Name", name); - m_Menu.setAD_Task_ID(id); - name = d_menu[i][5]; - id = get_IDWithColumn("AD_Workbench", "Name", name); - m_Menu.setAD_Workbench_ID(id); - name = d_menu[i][6]; - id = get_IDWithColumn("AD_Workflow", "Name", name); - m_Menu.setAD_Workflow_ID(id); - if (d_menu[i][7].compareTo(" ") > -1 ) - m_Menu.setAction(d_menu[i][7]); - m_Menu.setDescription(d_menu[i][8]); - m_Menu.setEntityType(d_menu[i][9]); - m_Menu.setIsReadOnly(Boolean.valueOf(d_menu[i][10]).booleanValue()); - m_Menu.setIsSOTrx(Boolean.valueOf(d_menu[i][11]).booleanValue()); - m_Menu.setIsSummary(Boolean.valueOf(d_menu[i][12]).booleanValue()); - m_Menu.setIsActive(Boolean.valueOf(d_menu[i][15]).booleanValue()); - if (m_Menu.save(m_trxName) == true){ - try { - idDetail = record_log (1, m_Menu.getName(),"Menu", m_Menu.get_ID(),AD_Backup_ID, Object_Status,"AD_Menu",get_IDWithColumn("AD_Table", "TableName", "AD_Menu")); - } catch (SAXException e) { - log.info ("setmenu:"+e); - } - } - else{ - try { - idDetail = record_log (0, m_Menu.getName(),"Menu", m_Menu.get_ID(),AD_Backup_ID, Object_Status,"AD_Menu",get_IDWithColumn("AD_Table", "TableName", "AD_Menu")); - } catch (SAXException e) { - log.info ("setmenu:"+e); - } - } - name = d_menu[i][13]; - id = get_ID("AD_Menu", name); - - String sql2 = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = 10" - + " AND Node_ID = " + menuid; - int countRecords = DB.getSQLValue(m_trxName,sql2); - if (countRecords>0){ - StringBuffer sqlC = new StringBuffer ("select * from AD_TREENODEMM where AD_Tree_ID = 10 and " - +" Node_ID =?"); - try { - PreparedStatement pstmt1 = DB.prepareStatement(sqlC.toString(), m_trxName); - pstmt1.setInt(1, menuid); - ResultSet rs1 = pstmt1.executeQuery(); - if (rs1.next()){ - - String colValue=null; - ResultSetMetaData meta = rs1.getMetaData(); - int columns = meta.getColumnCount(); - int tableID = get_IDWithColumn("AD_Table", "TableName", "AD_TreeNodeMM"); - - for (int q = 1; q <= columns; q++){ - - String col_Name = meta.getColumnName(q); - StringBuffer sql = new StringBuffer ("SELECT AD_Column_ID FROM AD_column WHERE Upper(ColumnName) = '"+col_Name+"' AND AD_Table_ID = ?"); - int columnID = DB.getSQLValue(m_trxName, sql.toString(),tableID); - sql = new StringBuffer ("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = '"+columnID+"'"); - int referenceID = DB.getSQLValue(m_trxName,sql.toString()); - int idBackup = MSequence.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Backup", m_trxName); - if (referenceID == 20|| referenceID == 28) - if (rs1.getObject(q).equals("Y")) - colValue = "true"; - else - colValue = "false"; - else - colValue = rs1.getObject(q).toString(); - - StringBuffer sqlD = new StringBuffer ("Insert INTO AD_Package_Imp_Backup" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," - + " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + idBackup - + ", " + idDetail - + ", " + AD_Package_Imp_ID - + ", " + tableID - + ", " + columnID - + ", " + referenceID - + ", '" +colValue - +"')"); - int no = DB.executeUpdate (sqlD.toString(), m_trxName); - if (no == -1) - log.info("Insert to import backup failed"); - } - - } - rs1.close(); - pstmt1.close(); - pstmt1 = null; - - } - catch (Exception e) { - log.info ("get_IDWithMasterID:"+e); - } - - - sqlB = new StringBuffer ("UPDATE AD_TREENODEMM " - + "SET Parent_ID = " + id - + " , SeqNo = " + d_menu[i][14] - + " WHERE AD_Tree_ID = 10" - + " AND Node_ID = " + m_Menu.getAD_Menu_ID()); - } else { - sqlB = new StringBuffer ("Insert INTO AD_TREENODEMM" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "Parent_ID, SeqNo, AD_Tree_ID, Node_ID)" - + "VALUES(0, 0, 0, 0, " - + id + ","+ d_menu[i][14]+", 10, "+m_Menu.getAD_Menu_ID()+")"); - } - DB.executeUpdate(sqlB.toString(), m_trxName); - } - } - - /** - * 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 (int success, String objectName,String objectType, int objectID,int objectIDBackup, String objectStatus, String tableName, int AD_Table_ID) throws SAXException{ - String recordLayout; - int id = 0; - if (success == 1){ - //hd_documemt.startElement("","","Successfull",attsOut); - recordLayout = "Type:"+objectType + " - Name:"+objectName + " - ID:"+objectID +" - Action:"+objectStatus+" - Success"; - hd_documemt.startElement("","","Success",attsOut); - hd_documemt.characters(recordLayout.toCharArray(),0,recordLayout.length()); - hd_documemt.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 = MSequence.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Detail", m_trxName); - - sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," - + " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + id - + ", " + AD_Package_Imp_ID - + ", '" + objectType - + "', '" + objectName - + "', '" + objectStatus - + "', 'Success'" - + ", "+objectID - + ", "+objectIDBackup - + ", '"+tableName - + "', "+AD_Table_ID - +")"); - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to import detail failed"); - - } - else{ - PK_Status = "Completed with errors"; - hd_documemt.startElement("","","Failure",attsOut); - recordLayout = "Type:"+objectType + " - Name:"+tableName + " - ID:"+objectID +" - Action:"+objectStatus+" - Failure"; - //hd_documemt.startElement("","","Success",attsOut); - hd_documemt.characters(recordLayout.toCharArray(),0,recordLayout.length()); - //hd_documemt.endElement("","","Success"); - hd_documemt.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 = MSequence.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Detail", m_trxName); - - sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," - + " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + id - + ", " + AD_Package_Imp_ID - + ", '" + objectType - + "', '" + objectName - + "', '" + objectStatus - + "', 'Failure'" - + ", "+objectID - + ", "+objectIDBackup - + ", '"+tableName - + "', "+AD_Table_ID - +")"); - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to import detail failed"); - } - - Object_Status = "Status not set"; - return id; - } - - /** * Check if Package History Table exists in database. If not create * * @param tablename @@ -3372,29 +427,29 @@ public class PackInHandler extends DefaultHandler { } else { if (tablename.equals("AD_Package_Imp")){ - sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( " - + tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " - + "AD_CLIENT_ID NUMBER(10) NOT NULL, " - + "AD_ORG_ID NUMBER(10) NOT NULL, " - + "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " - + "CREATED DATE DEFAULT SYSDATE NOT NULL, " - + "CREATEDBY NUMBER(10) NOT NULL, " - + "UPDATED DATE DEFAULT SYSDATE NOT NULL, " - + "UPDATEDBY NUMBER(10) NOT NULL, " - + "NAME NVARCHAR2(60) NOT NULL, " - + "PK_STATUS NVARCHAR2(22), " - + "RELEASENO NVARCHAR2(20), " - + "PK_VERSION NVARCHAR2(20), " - + "VERSION NVARCHAR2(20), " - + "DESCRIPTION NVARCHAR2(1000) NOT NULL, " - + "EMAIL NVARCHAR2(60), " - + "PROCESSED CHAR(1) DEFAULT 'N', " - + "PROCESSING CHAR(1) DEFAULT 'N', " - + "CREATOR VARCHAR2(60 ), " - + "CREATORCONTACT VARCHAR2(255), " - +" CREATEDDATE VARCHAR2(25), " - + "UPDATEDDATE VARCHAR2(25), " - + "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + 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, @@ -3409,29 +464,29 @@ public class PackInHandler extends DefaultHandler { } } if (tablename.equals("AD_Package_Imp_Inst")){ - sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( " - + tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " - + "AD_CLIENT_ID NUMBER(10) NOT NULL, " - + "AD_ORG_ID NUMBER(10) NOT NULL, " - + "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " - + "CREATED DATE DEFAULT SYSDATE NOT NULL, " - + "CREATEDBY NUMBER(10) NOT NULL, " - + "UPDATED DATE DEFAULT SYSDATE NOT NULL, " - + "UPDATEDBY NUMBER(10) NOT NULL, " - + "NAME NVARCHAR2(60) NOT NULL, " - + "PK_STATUS NVARCHAR2(22), " - + "RELEASENO NVARCHAR2(20), " - + "PK_VERSION NVARCHAR2(20), " - + "VERSION NVARCHAR2(20), " - + "DESCRIPTION NVARCHAR2(1000) NOT NULL, " - + "EMAIL NVARCHAR2(60), " - + "PROCESSED CHAR(1) DEFAULT 'N', " - + "PROCESSING CHAR(1) DEFAULT 'N', " - + "CREATOR VARCHAR2(60 ), " - + "CREATORCONTACT VARCHAR2(255), " - +" CREATEDDATE VARCHAR2(25), " - + "UPDATEDDATE VARCHAR2(25), " - + "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + 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, @@ -3446,26 +501,26 @@ public class PackInHandler extends DefaultHandler { } } if (tablename.equals("AD_Package_Imp_Detail")){ - sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( " - + tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " - + "AD_CLIENT_ID NUMBER(10) NOT NULL, " - + "AD_ORG_ID NUMBER(10) NOT NULL, " - + "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " - + "CREATED DATE DEFAULT SYSDATE NOT NULL, " - + "CREATEDBY NUMBER(10) NOT NULL, " - + "UPDATED DATE DEFAULT SYSDATE NOT NULL, " - + "UPDATEDBY NUMBER(10) NOT NULL, " - + "NAME NVARCHAR2(60), " - + "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " - + "AD_ORIGINAL_ID Number(10) NOT NULL, " - + "AD_BACKUP_ID Number(10), " - + "ACTION NVARCHAR2(20), " - + "SUCCESS NVARCHAR2(20), " - + "TYPE NVARCHAR2(60), " - + "TABLENAME NVARCHAR2(60), " - + "AD_TABLE_ID NUMBER(10), " - + "UNINSTALL CHAR(1), " - + "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + 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, @@ -3480,25 +535,25 @@ public class PackInHandler extends DefaultHandler { } } if (tablename.equals("AD_Package_Imp_Backup")){ - sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( " - + tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " - + "AD_CLIENT_ID NUMBER(10) NOT NULL, " - + "AD_ORG_ID NUMBER(10) NOT NULL, " - + "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " - + "CREATED DATE DEFAULT SYSDATE NOT NULL, " - + "CREATEDBY NUMBER(10) NOT NULL, " - + "UPDATED DATE DEFAULT SYSDATE NOT NULL, " - + "UPDATEDBY NUMBER(10) NOT NULL, " - + "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " - + "AD_PACKAGE_IMP_DETAIL_ID Number(10) NOT NULL, " - + "AD_TABLE_ID NUMBER(10), " - + "AD_COLUMN_ID NUMBER(10), " - + "AD_REFERENCE_ID NUMBER(10), " - + "AD_PACKAGE_IMP_BCK_DIR NVARCHAR2(255), " - + "AD_PACKAGE_IMP_ORG_DIR NVARCHAR2(255), " - + "COLVALUE NVARCHAR2(2000), " - + "UNINSTALL CHAR(1), " - + "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + 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, @@ -3534,280 +589,6 @@ public class PackInHandler extends DefaultHandler { } } - /** - * Find and replace code - * - * @param file name - * @param old string - * @param new string - * - */ - public static int readReplace(String fname, String oldPattern, String replPattern){ - String line; - StringBuffer sb = new StringBuffer(); - - try { - - FileInputStream fis = new FileInputStream(fname); - BufferedReader reader=new BufferedReader ( new InputStreamReader(fis)); - while((line = reader.readLine()) != null) { - line = line.replaceAll(oldPattern, replPattern); - System.err.println(line); - sb.append(line+"\n"); - } - reader.close(); - BufferedWriter out=new BufferedWriter ( new FileWriter(fname)); - out.write(sb.toString()); - out.close(); - } - catch (Throwable e) { - System.err.println("error replacing codesnipit "+e); - return -1; - } - return 0; - } - - /** - * Make backup copy of record. - * - * @param tablename - * - * - * - */ - public int copyRecord(String tableName,PO from){ - // Create new record - int idBackup = 0; - String colValue=null; - int tableID = get_IDWithColumn("AD_Table", "TableName", tableName); - POInfo poInfo = POInfo.getPOInfo(m_ctx, tableID); - for (int i = 0; i < poInfo.getColumnCount(); i++){ - String colName = poInfo.getColumnName(i); - colValue=null; - - int columnID =get_IDWithMasterAndColumn ("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(m_trxName,sqlD.toString()); - - idBackup = MSequence.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Backup", m_trxName); - - sqlD = new StringBuffer("SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL"); - int idDetail = DB.getSQLValue(m_trxName,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 - - sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Backup" - + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " - + "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," - + " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" - + "VALUES(" - + " "+ Env.getAD_Client_ID(m_ctx) - + ", "+ Env.getAD_Org_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", "+ Env.getAD_User_ID(m_ctx) - + ", " + idBackup - + ", " + idDetail - + ", " + AD_Package_Imp_ID - + ", " + tableID - + ", " + columnID - + ", " + referenceID - + ", '" + (colValue != null ? colValue : from.get_Value(i)) - +"')"); - - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to import backup failed"); - //} - } - return idBackup; - } - - /** - * Check if column exists in database and modify. If not create column. - * - * @param tablename - * @param columnname - * @param v_AD_Reference_ID - * @param v_FieldLength - * @param v_DefaultValue - * @param v_IsMandatory - * - */ - public int createcolumn (MColumn column){ - MTable table = new MTable(m_ctx, column.getAD_Table_ID(), m_trxName); - if (table.isView()) - return 0; - - int no = 0; - - String sql = null; - ResultSet rst = null; - ResultSet rsc = null; - try { - // Find Column in Database - DatabaseMetaData md = DB.getConnectionRO().getMetaData(); - String catalog = DB.getDatabase().getCatalog(); - String schema = DB.getDatabase().getSchema(); - String tableName = table.getTableName(); - String columnName = column.getColumnName(); - if (DB.isOracle()) { - tableName = tableName.toUpperCase(); - columnName = columnName.toUpperCase(); - } else if (DB.isPostgreSQL()) { - tableName = tableName.toLowerCase(); - columnName = columnName.toLowerCase(); - } - - rst = md.getTables(catalog, schema, tableName, new String[] {"TABLE"}); - if (! rst.next()) { - // table doesn't exist - sql = table.getSQLCreate (); - } else { - // - rsc = md.getColumns(catalog, schema, tableName, columnName); - if (rsc.next()) - { - // update existing column - boolean notNull = DatabaseMetaData.columnNoNulls == rsc.getInt("NULLABLE"); - sql = column.getSQLModify(table, column.isMandatory() != notNull); - } else { - // No existing column - sql = column.getSQLAdd(table); - } - rsc.close(); - rsc = null; - } - - rst.close(); - rst = null; - log.info(sql); - - if (sql.indexOf(DB.SQLSTATEMENT_SEPARATOR) == -1) - { - no = DB.executeUpdate(sql, false, m_trxName); - } - else - { - String statements[] = sql.split(DB.SQLSTATEMENT_SEPARATOR); - for (int i = 0; i < statements.length; i++) - { - int count = DB.executeUpdate(statements[i], false, m_trxName); - no += count; - } - } - - } catch (SQLException e) { - e.printStackTrace(); - if (rsc != null) { - try { - rsc.close(); - } catch (SQLException e1) { } - rsc = null; - } - if (rst != null) { - try { - rst.close(); - } catch (SQLException e1) { } - rst = null; - } - return 0; - } - - // postgres requires commit on DDL (ALTER,CREATE) - if (DB.isPostgreSQL()) { - try { - DB.commit(true, m_trxName); - } catch (SQLException e) { - e.printStackTrace(); - return 0; - } - } - - return 1; - } - - /** - * 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("Can't find file "); - - 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("Can't find file "); - - 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."); - System.out.println(e.toString()); - - success = -1; - } - return success; - } - /** * Receive notification of the end of an element. * @param uri namespace @@ -3822,25 +603,15 @@ public class PackInHandler extends DefaultHandler { elementValue = qName; else elementValue = uri + localName; - // log.info("endElement: "+elementValue); - /* **************************************** - adempieredata Handler. - **************************************** */ - // row element, adempieredata - if (elementValue.equals("drow")){ - if (genericPO.save(m_trxName)== true) - record_log (1, genericPO.get_TableName(),"Data", genericPO.get_ID(),AD_Backup_ID, Object_Status,d_tablename,get_IDWithColumn("AD_Table", "TableName", d_tablename)); - else - record_log (0, genericPO.get_TableName(),"Data", genericPO.get_ID(),AD_Backup_ID, Object_Status,d_tablename,get_IDWithColumn("AD_Table", "TableName", d_tablename)); - - genericPO = null; - } - else if (elementValue.equals("adempiereAD")){ + + if (elementValue.equals("adempiereAD")){ + processDeferElements(); + processMenuElements(); if (!PK_Status.equals("Completed with errors")) PK_Status = "Completed successfully"; //Update package history log with package status - sqlB = new StringBuffer ("UPDATE AD_Package_Imp " + 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); @@ -3855,17 +626,58 @@ public class PackInHandler extends DefaultHandler { if (no == -1) log.info("Update to package list failed"); - hd_documemt.endElement("","","adempiereDocument"); - hd_documemt.endDocument(); + hd_document.endElement("","","adempiereDocument"); + hd_document.endDocument(); try { fw_document.close(); } catch (Exception e) {} + } else { + Element e = stack.pop(); + ElementHandler handler = handlers.get(elementValue); + if (handler != null) + handler.endElement(m_ctx, e); + if (e.defer) + defer.add(new DeferEntry(e, false)); } } // endElement - // globalqss - add support for trx in 3.1.2 + 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) { + d.element.defer = false; + 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); + } + int endSize = defer.size(); + if (startSize == endSize) break; + } while (defer.size() > 0); + } + + // globalqss - add support for trx in 3.1.2 public void set_TrxName(String trxName) { m_trxName = trxName; } @@ -3875,4 +687,13 @@ public class PackInHandler extends DefaultHandler { m_ctx = ctx; } + class DeferEntry { + Element element; + boolean startElement = false; + + DeferEntry(Element e, boolean b) { + element = e; + startElement = b; + } + } } // PackInHandler diff --git a/base/src/org/adempiere/pipo/PackOut.java b/base/src/org/adempiere/pipo/PackOut.java index 9aae7deb8b..78d67916ec 100644 --- a/base/src/org/adempiere/pipo/PackOut.java +++ b/base/src/org/adempiere/pipo/PackOut.java @@ -13,12 +13,13 @@ * * Copyright (C) * 2004 Robert KLEIN. robeklein@hotmail.com * - * Contributor(s): ______________________________________. + * Contributor(s): Low Heng Sin hengsin@avantz.com *****************************************************************************/ package org.adempiere.pipo; import java.io.*; import java.sql.*; +import java.util.Properties; import java.util.logging.Level; import javax.xml.transform.OutputKeys; @@ -28,37 +29,30 @@ import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import org.adempiere.pipo.CreateZipFile; -import org.compiere.model.X_AD_Column; -import org.compiere.model.X_AD_Field; +import org.adempiere.pipo.handler.CodeSnipitElementHandler; +import org.adempiere.pipo.handler.DataElementHandler; +import org.adempiere.pipo.handler.DistFileElementHandler; +import org.adempiere.pipo.handler.DynValRuleElementHandler; +import org.adempiere.pipo.handler.FormElementHandler; +import org.adempiere.pipo.handler.ImpFormatElementHandler; +import org.adempiere.pipo.handler.MenuElementHandler; +import org.adempiere.pipo.handler.MessageElementHandler; +import org.adempiere.pipo.handler.PrintFormatElementHandler; +import org.adempiere.pipo.handler.ProcessElementHandler; +import org.adempiere.pipo.handler.ReferenceElementHandler; +import org.adempiere.pipo.handler.ReportViewElementHandler; +import org.adempiere.pipo.handler.RoleElementHandler; +import org.adempiere.pipo.handler.SQLStatementElementHandler; +import org.adempiere.pipo.handler.TableElementHandler; +import org.adempiere.pipo.handler.TaskElementHandler; +import org.adempiere.pipo.handler.WindowElementHandler; +import org.adempiere.pipo.handler.WorkbenchElementHandler; +import org.adempiere.pipo.handler.WorkflowElementHandler; import org.compiere.model.X_AD_Package_Exp; import org.compiere.model.X_AD_Package_Exp_Detail; -import org.compiere.model.X_AD_Process; -import org.compiere.model.X_AD_Process_Para; -import org.compiere.model.X_AD_Tab; -import org.compiere.model.X_AD_Table; -import org.compiere.model.X_AD_Window; -import org.compiere.model.X_AD_Preference; -import org.compiere.model.X_AD_Menu; -import org.compiere.model.X_AD_PrintFormatItem; -import org.compiere.model.X_AD_Task; -import org.compiere.model.X_AD_Form; -import org.compiere.model.X_AD_Workbench; -import org.compiere.model.X_AD_WorkbenchWindow; import org.compiere.model.X_AD_Reference; -import org.compiere.model.X_AD_PrintFormat; -import org.compiere.model.X_AD_ImpFormat; -import org.compiere.model.X_AD_ImpFormat_Row; -import org.compiere.model.X_AD_Ref_List; -import org.compiere.model.X_AD_ReportView; -import org.compiere.model.X_AD_ReportView_Col; -import org.compiere.model.X_AD_Role; -import org.compiere.model.X_AD_Workflow; -import org.compiere.model.X_AD_Val_Rule; -import org.compiere.model.X_AD_Message; -import org.compiere.model.X_AD_WF_Node; -import org.compiere.model.X_AD_WF_NodeNext; -import org.compiere.model.X_AD_WF_NextCondition; import org.compiere.util.DB; +import org.compiere.util.Env; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import org.compiere.process.*; @@ -77,40 +71,33 @@ public class PackOut extends SvrProcess { /** Record ID */ private int p_PackOut_ID = 0; - private X_AD_Window m_Window = null; - private X_AD_Process_Para m_Processpara = null; - private X_AD_Table m_Table = null; - private X_AD_Workflow m_Workflow = null; - private X_AD_Message m_Message = null; - private X_AD_WF_Node m_WF_Node = null; - private X_AD_WF_NodeNext m_WF_NodeNext = null; - private X_AD_WF_NextCondition m_WF_NodeNextCondition = null; - private X_AD_Val_Rule m_ValRule = null; - private X_AD_Column m_Column = null; - private X_AD_Tab m_Tab = null; - private X_AD_PrintFormat m_Printformat = null; - private X_AD_Field m_Field = null; - private X_AD_Menu m_Menu = null; - private X_AD_Task m_Task = null; - private X_AD_PrintFormatItem m_PrintFormatItem = null; - private X_AD_Form m_Form = null; - private X_AD_Workbench m_Workbench = null; - private X_AD_WorkbenchWindow m_Workbenchwindow = null; - private X_AD_Reference m_Reference = null; - private X_AD_Ref_List m_Ref_List = null; - private X_AD_ReportView m_Reportview = null; - private X_AD_ReportView_Col m_Reportview_Col = null; - private X_AD_Role m_Role = null; - private X_AD_Preference m_Preference= null; - private X_AD_ImpFormat m_ImpFormat= null; - private X_AD_ImpFormat_Row m_ImpFormat_Row= null; - private String PackOutVer = "005"; + private String PackOutVer = "005"; private String packagedir = null; private String packagename = null; private String includesdir = null; - private int Table_ID[] = new int [1000]; - private int Table_Count = 0; - String fileSeperator=null; + + private Properties localContext = null; + + ProcessElementHandler processHandler = new ProcessElementHandler(); + TaskElementHandler taskHandler = new TaskElementHandler(); + FormElementHandler formHandler = new FormElementHandler(); + WindowElementHandler windowHandler = new WindowElementHandler(); + MenuElementHandler menuHandler = new MenuElementHandler(); + ReportViewElementHandler reportViewHandler = new ReportViewElementHandler(); + DataElementHandler dataHandler = new DataElementHandler(); + TableElementHandler tableHandler = new TableElementHandler(); + WorkbenchElementHandler workbenchHandler = new WorkbenchElementHandler(); + RoleElementHandler roleHandler = new RoleElementHandler(); + SQLStatementElementHandler sqlHandler = new SQLStatementElementHandler(); + ImpFormatElementHandler impFormtHandler = new ImpFormatElementHandler(); + CodeSnipitElementHandler codeHandler = new CodeSnipitElementHandler(); + WorkflowElementHandler workflowHandler = new WorkflowElementHandler(); + DynValRuleElementHandler dynValRuleHandler = new DynValRuleElementHandler(); + MessageElementHandler messageHandler = new MessageElementHandler(); + PrintFormatElementHandler printFormatHandler = new PrintFormatElementHandler(); + DistFileElementHandler distFileHandler = new DistFileElementHandler(); + ReferenceElementHandler referenceHandler = new ReferenceElementHandler(); + /** * Prepare - e.g., get Parameters. */ @@ -131,8 +118,10 @@ public class PackOut extends SvrProcess */ protected String doIt() throws java.lang.Exception { - OutputStream fw_document = null; - OutputStream fw_menu = null; + initContext(); + + OutputStream packageDocStream = null; + OutputStream packOutDocStream = null; log.info("doIt - AD_PACKAGE_EXP_ID=" + p_PackOut_ID); if (p_PackOut_ID == 0) throw new IllegalArgumentException("No Record"); @@ -144,95 +133,94 @@ public class PackOut extends SvrProcess ResultSet rs1 = pstmt1.executeQuery(); while (rs1.next()){ //Create the package documentation - fileSeperator = File.separator; packagedir = rs1.getString(X_AD_Package_Exp.COLUMNNAME_File_Directory).trim(); if (!packagedir.endsWith("/") && !packagedir.endsWith("\\")) - packagedir += fileSeperator; + packagedir += File.separator; packagename = packagedir + rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name); - includesdir = rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name) + fileSeperator+"**"; - boolean success = (new File(packagename+fileSeperator+"doc"+fileSeperator )).mkdirs(); - String file_document = packagename +fileSeperator+ "doc"+fileSeperator+rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)+"Doc.xml"; - fw_document = new FileOutputStream (file_document, false); - StreamResult streamResult_document = new StreamResult(fw_document); + includesdir = rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name) + File.separator +"**"; + boolean success = (new File(packagename+File.separator+"doc"+File.separator)).mkdirs(); + String file_document = packagename+File.separator+"doc"+File.separator+rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)+"Doc.xml"; + packageDocStream = new FileOutputStream (file_document, false); + StreamResult streamResult_document = new StreamResult(packageDocStream); SAXTransformerFactory tf_document = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - TransformerHandler hd_documemt = tf_document.newTransformerHandler(); - Transformer serializer_document = hd_documemt.getTransformer(); + TransformerHandler packageDocument = tf_document.newTransformerHandler(); + Transformer serializer_document = packageDocument.getTransformer(); serializer_document.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); serializer_document.setOutputProperty(OutputKeys.INDENT,"yes"); - hd_documemt.setResult(streamResult_document); - hd_documemt.startDocument(); + packageDocument.setResult(streamResult_document); + packageDocument.startDocument(); AttributesImpl atts = new AttributesImpl(); atts.clear(); - hd_documemt.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\""); - hd_documemt.startElement("","","adempiereDocument",atts); - hd_documemt.startElement("","","header",atts); - hd_documemt.characters((rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)+" Package Description").toCharArray(),0,(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)+" Package Description").length()); - hd_documemt.endElement("","","header"); - hd_documemt.startElement("","","H1",atts); - hd_documemt.characters(("Package Name:" ).toCharArray(),0,("Package Name:" ).length()); - hd_documemt.endElement("","","H1"); - hd_documemt.startElement("","","packagename",atts); - hd_documemt.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name).length()); - hd_documemt.endElement("","","packagename"); - hd_documemt.startElement("","","H1",atts); - hd_documemt.characters(("Creator:" ).toCharArray(),0,("Creator:").length()); - hd_documemt.endElement("","","H1"); - hd_documemt.startElement("","","creator",atts); - hd_documemt.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_UserName).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_UserName).length()); - hd_documemt.endElement("","","creator"); - hd_documemt.startElement("","","H1",atts); - hd_documemt.characters(("Email Address:" ).toCharArray(),0,("Email Address:" ).length()); - hd_documemt.endElement("","","H1"); - hd_documemt.startElement("","","creatorcontact",atts); - hd_documemt.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_EMail).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_EMail).length()); - hd_documemt.endElement("","","creatorcontact"); - hd_documemt.startElement("","","H1",atts); - hd_documemt.characters(("Created:" ).toCharArray(),0,("Created:" ).length()); - hd_documemt.endElement("","","H1"); - hd_documemt.startElement("","","createddate",atts); - hd_documemt.characters(rs1.getString("Created").toString().toCharArray(),0,rs1.getString("Created").toString().length()); - hd_documemt.endElement("","","createddate"); - hd_documemt.startElement("","","H1",atts); - hd_documemt.characters(("Updated:" ).toCharArray(),0,("Updated:" ).length()); - hd_documemt.endElement("","","H1"); - hd_documemt.startElement("","","updateddate",atts); - hd_documemt.characters(rs1.getString("Updated").toString().toCharArray(),0,rs1.getString("Updated".toString()).length()); - hd_documemt.endElement("","","updateddate"); - hd_documemt.startElement("","","H1",atts); - hd_documemt.characters(("Description:" ).toCharArray(),0,("Description:" ).length()); - hd_documemt.endElement("","","H1"); - hd_documemt.startElement("","","description",atts); - hd_documemt.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Description).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_Description).length()); - hd_documemt.endElement("","","description"); - hd_documemt.startElement("","","H1",atts); - hd_documemt.characters(("Instructions:" ).toCharArray(),0,("Instructions:" ).length()); - hd_documemt.endElement("","","H1"); - hd_documemt.startElement("","","instructions",atts); - hd_documemt.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Instructions).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_Instructions).length()); - hd_documemt.endElement("","","instructions"); - hd_documemt.startElement("","","H1",atts); - hd_documemt.characters(("Files in Package:" ).toCharArray(),0,("Files in Package:" ).length()); - hd_documemt.endElement("","","H1"); - hd_documemt.startElement("","","file",atts); - hd_documemt.characters(("File: PackOut.xml").toCharArray(),0,("File: PackOut.xml").length()); - hd_documemt.endElement("","","file"); - hd_documemt.startElement("","","filedirectory",atts); - hd_documemt.characters("Directory: \\dict\\".toCharArray(),0,("Directory: \\dict\\").length()); - hd_documemt.endElement("","","filedirectory"); - hd_documemt.startElement("","","filenotes",atts); - hd_documemt.characters("Notes: Contains all application/object settings for package".toCharArray(),0,"Notes: Contains all application/object settings for package".length()); - hd_documemt.endElement("","","filenotes"); - success = (new File(packagename+fileSeperator+ "dict"+fileSeperator)).mkdirs(); - String file_menu = packagename+fileSeperator+ "dict"+fileSeperator+"PackOut.xml"; - fw_menu = new FileOutputStream (file_menu, false); - StreamResult streamResult_menu = new StreamResult(fw_menu); + packageDocument.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\""); + packageDocument.startElement("","","adempiereDocument",atts); + packageDocument.startElement("","","header",atts); + packageDocument.characters((rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)+" Package Description").toCharArray(),0,(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)+" Package Description").length()); + packageDocument.endElement("","","header"); + packageDocument.startElement("","","H1",atts); + packageDocument.characters(("Package Name:" ).toCharArray(),0,("Package Name:" ).length()); + packageDocument.endElement("","","H1"); + packageDocument.startElement("","","packagename",atts); + packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name).length()); + packageDocument.endElement("","","packagename"); + packageDocument.startElement("","","H1",atts); + packageDocument.characters(("Creator:" ).toCharArray(),0,("Creator:").length()); + packageDocument.endElement("","","H1"); + packageDocument.startElement("","","creator",atts); + packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_UserName).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_UserName).length()); + packageDocument.endElement("","","creator"); + packageDocument.startElement("","","H1",atts); + packageDocument.characters(("Email Address:" ).toCharArray(),0,("Email Address:" ).length()); + packageDocument.endElement("","","H1"); + packageDocument.startElement("","","creatorcontact",atts); + packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_EMail).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_EMail).length()); + packageDocument.endElement("","","creatorcontact"); + packageDocument.startElement("","","H1",atts); + packageDocument.characters(("Created:" ).toCharArray(),0,("Created:" ).length()); + packageDocument.endElement("","","H1"); + packageDocument.startElement("","","createddate",atts); + packageDocument.characters(rs1.getString("Created").toString().toCharArray(),0,rs1.getString("Created").toString().length()); + packageDocument.endElement("","","createddate"); + packageDocument.startElement("","","H1",atts); + packageDocument.characters(("Updated:" ).toCharArray(),0,("Updated:" ).length()); + packageDocument.endElement("","","H1"); + packageDocument.startElement("","","updateddate",atts); + packageDocument.characters(rs1.getString("Updated").toString().toCharArray(),0,rs1.getString("Updated".toString()).length()); + packageDocument.endElement("","","updateddate"); + packageDocument.startElement("","","H1",atts); + packageDocument.characters(("Description:" ).toCharArray(),0,("Description:" ).length()); + packageDocument.endElement("","","H1"); + packageDocument.startElement("","","description",atts); + packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Description).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_Description).length()); + packageDocument.endElement("","","description"); + packageDocument.startElement("","","H1",atts); + packageDocument.characters(("Instructions:" ).toCharArray(),0,("Instructions:" ).length()); + packageDocument.endElement("","","H1"); + packageDocument.startElement("","","instructions",atts); + packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Instructions).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_Instructions).length()); + packageDocument.endElement("","","instructions"); + packageDocument.startElement("","","H1",atts); + packageDocument.characters(("Files in Package:" ).toCharArray(),0,("Files in Package:" ).length()); + packageDocument.endElement("","","H1"); + packageDocument.startElement("","","file",atts); + packageDocument.characters(("File: PackOut.xml").toCharArray(),0,("File: PackOut.xml").length()); + packageDocument.endElement("","","file"); + packageDocument.startElement("","","filedirectory",atts); + packageDocument.characters("Directory: \\dict\\".toCharArray(),0,("Directory: \\dict\\").length()); + packageDocument.endElement("","","filedirectory"); + packageDocument.startElement("","","filenotes",atts); + packageDocument.characters("Notes: Contains all application/object settings for package".toCharArray(),0,"Notes: Contains all application/object settings for package".length()); + packageDocument.endElement("","","filenotes"); + success = (new File(packagename+File.separator+ "dict"+File.separator)).mkdirs(); + String file_menu = packagename+File.separator+ "dict"+File.separator+"PackOut.xml"; + packOutDocStream = new FileOutputStream (file_menu, false); + StreamResult streamResult_menu = new StreamResult(packOutDocStream); SAXTransformerFactory tf_menu = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - TransformerHandler hd_menu = tf_menu.newTransformerHandler(); - Transformer serializer_menu = hd_menu.getTransformer(); + TransformerHandler packOutDocument = tf_menu.newTransformerHandler(); + Transformer serializer_menu = packOutDocument.getTransformer(); serializer_menu.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); serializer_menu.setOutputProperty(OutputKeys.INDENT,"yes"); - hd_menu.setResult(streamResult_menu); - hd_menu.startDocument(); + packOutDocument.setResult(streamResult_menu); + packOutDocument.startDocument(); atts.clear(); atts.addAttribute("","","Name","CDATA",rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)); atts.addAttribute("","","Version","CDATA",rs1.getString(X_AD_Package_Exp.COLUMNNAME_PK_Version)); @@ -245,7 +233,7 @@ public class PackOut extends SvrProcess atts.addAttribute("","","updateddate","CDATA",rs1.getString("Updated")); atts.addAttribute("","","PackOutVer","CDATA",PackOutVer); - hd_menu.startElement("","","adempiereAD",atts); + packOutDocument.startElement("","","adempiereAD",atts); atts.clear(); String sql = "SELECT * FROM AD_Package_Exp_Detail WHERE AD_Package_Exp_ID = "+p_PackOut_ID+" ORDER BY Line ASC"; @@ -258,63 +246,54 @@ public class PackOut extends SvrProcess String Type = rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Type); log.info(rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Line)); if (Type.compareTo("M") == 0){ - m_Menu = new X_AD_Menu (getCtx(), rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID), null); - if (m_Menu.isSummary() == false) { - CreateApplication (atts, hd_menu, rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID)); - } - else { - atts = createmenuBinding(atts,m_Menu); - hd_menu.startElement("","","menu",atts); - CreateModule (atts, hd_menu, rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID)); - hd_menu.endElement("","","menu"); - } + createMenu(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID), atts, packOutDocument ); } else if (Type.compareTo("P") == 0) - CreateProcess ( rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID), atts, hd_menu ); + createProcess ( rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID), atts, packOutDocument ); else if (Type.compareTo("R") == 0) - CreateReportview ( rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID), atts, hd_menu ); + createReportview ( rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID), atts, packOutDocument ); else if (Type.compareTo("D") == 0) - CreateData ( rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement), atts, hd_menu ); + createData ( rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement), atts, packOutDocument ); else if (Type.compareTo("T") == 0) - CreateTable (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID), atts, hd_menu); + createTable (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID), atts, packOutDocument); else if (Type.compareTo("X") == 0) - CreateForm (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID), atts, hd_menu); + createForm (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID), atts, packOutDocument); else if (Type.compareTo("W") == 0) - CreateWindow (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID), atts, hd_menu); + createWindow (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID), atts, packOutDocument); else if (Type.compareTo("B") == 0) - CreateWorkbench (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workbench_ID), atts, hd_menu); + createWorkbench (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workbench_ID), atts, packOutDocument); else if (Type.compareTo("S") == 0) - CreateRoles (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID), atts, hd_menu); + createRoles (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID), atts, packOutDocument); else if (Type.compareTo("SQL") == 0) - CreateSQL (rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_DBType), atts, hd_menu); + createSQL (rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_DBType), atts, packOutDocument); else if (Type.compareTo("IMP") == 0) - CreateImp (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID), atts, hd_menu); + createImpFormat (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID), atts, packOutDocument); else if (Type.compareTo("SNI") == 0) - CreateSnipit( + createSnipit( rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Destination_Directory), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Destination_FileName), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo), - atts, hd_menu); + atts, packOutDocument); else if (Type.compareTo("F") == 0) - CreateWorkflow (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID), atts, hd_menu); + createWorkflow (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID), atts, packOutDocument); else if (Type.compareTo("V") == 0) - CreateDynamicRuleValidation(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID), atts, hd_menu); + createDynamicRuleValidation(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID), atts, packOutDocument); else if (Type.compareTo("MSG") == 0) - CreateMessage(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID), atts, hd_menu); + createMessage(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID), atts, packOutDocument); else if (Type.compareTo("PFT") == 0) - CreatePrintFormat(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID), atts, hd_menu); + createPrintFormat(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID), atts, packOutDocument); else if (Type.compareTo("C") == 0){ - log.log(Level.SEVERE,"In PackOut.java handling Code or Other 2pack module creation"); + log.log(Level.INFO,"In PackOut.java handling Code or Other 2pack module creation"); String fullDirectory = rs1.getString(X_AD_Package_Exp.COLUMNNAME_File_Directory) + rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)+rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory); - log.log(Level.SEVERE,"fullDirectory" + fullDirectory); + log.log(Level.INFO,"fullDirectory" + fullDirectory); String targetDirectoryModified=null; char fileseperator1 = '/'; char fileseperator2 = '\\'; //Correct package for proper file seperator - if (fileSeperator.equals("/")){ + if (File.separator.equals("/")){ targetDirectoryModified = fullDirectory.replace(fileseperator2,fileseperator1); } else @@ -325,13 +304,13 @@ public class PackOut extends SvrProcess fullDirectory = rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory); targetDirectoryModified=null; //Correct package for proper file seperator - if (fileSeperator.equals("/")){ + if (File.separator.equals("/")){ targetDirectoryModified = fullDirectory.replace(fileseperator2,fileseperator1); } else targetDirectoryModified = fullDirectory.replace(fileseperator2,fileseperator1); - CopyCode( + copyCode( targetDirectoryModified + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName), target_File + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName)); @@ -343,49 +322,45 @@ public class PackOut extends SvrProcess String destinationDirectoryModified=null; //Correct package for proper file seperator - if (fileSeperator.equals("/")){ + if (File.separator.equals("/")){ destinationDirectoryModified = fullDirectory.replace(fileseperator2,fileseperator1); } else destinationDirectoryModified = fullDirectory.replace(fileseperator2,fileseperator1); - DistributeFile( + createDistributeFile( rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo), destinationDirectoryModified, atts, - hd_menu); + packOutDocument); } if(rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName) != null){ - hd_documemt.startElement("","","file",atts); - hd_documemt.characters(("File: "+rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName)).toCharArray(),0,("File: "+rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName)).length()); - hd_documemt.endElement("","","file"); + packageDocument.startElement("","","file",atts); + packageDocument.characters(("File: "+rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName)).toCharArray(),0,("File: "+rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName)).length()); + packageDocument.endElement("","","file"); } - hd_documemt.startElement("","","filedirectory",atts); - hd_documemt.characters( + packageDocument.startElement("","","filedirectory",atts); + packageDocument.characters( ("Directory: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory)).toCharArray(), 0, ("Directory: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory)).length()); - hd_documemt.endElement("","","filedirectory"); + packageDocument.endElement("","","filedirectory"); - hd_documemt.startElement("","","filenotes",atts); - hd_documemt.characters( + packageDocument.startElement("","","filenotes",atts); + packageDocument.characters( ("Notes: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Description)).toCharArray(), 0, (("Notes: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Description)).length())); - hd_documemt.endElement("","","filenotes"); + packageDocument.endElement("","","filenotes"); } } rs.close(); pstmt.close(); pstmt = null; } - catch (Exception e) - { - log.log(Level.SEVERE,"getWindows"+ e); - } finally { try @@ -397,12 +372,13 @@ public class PackOut extends SvrProcess {} pstmt = null; } - atts.clear(); - hd_menu.startElement("","","menuset",atts); - hd_menu.endElement("","","menuset"); - hd_menu.endElement("","","adempiereAD"); - hd_menu.endDocument();hd_documemt.endElement("","","adempiereDocument"); - hd_documemt.endDocument(); + atts.clear(); + //no longer use + //packOutDocument.startElement("","","menuset",atts); + //packOutDocument.endElement("","","menuset"); + packOutDocument.endElement("","","adempiereAD"); + packOutDocument.endDocument();packageDocument.endElement("","","adempiereDocument"); + packageDocument.endDocument(); //m_Exp.setProcessed(true); //m_Exp.save(); } @@ -412,7 +388,8 @@ public class PackOut extends SvrProcess } catch (Exception e) { - log.log(Level.SEVERE,"getWindows", e); + log.log(Level.SEVERE,e.getLocalizedMessage(), e); + throw e; } finally { @@ -420,20 +397,22 @@ public class PackOut extends SvrProcess { if (pstmt1 != null) pstmt1.close (); - fw_document.close(); - fw_menu.close(); } catch (Exception e) {} pstmt1 = null; + + // Close streams - teo_sarca [ 1704762 ] + if (packageDocStream != null) + try { + packageDocStream.close(); + } catch (Exception e) {} + if (packOutDocStream != null) + try { + packOutDocStream.close(); + } catch (Exception e) {} } - // Close streams - teo_sarca [ 1704762 ] - if (fw_document != null) - fw_document.close(); - if (fw_menu != null) - fw_menu.close(); - //create compressed packages //set the files File srcFolder = new File(""); @@ -461,3102 +440,179 @@ public class PackOut extends SvrProcess return "Finish Process"; } // doIt - public void CreateApplication (AttributesImpl atts, TransformerHandler hd_menu, int menu_id) throws SAXException - { - String sql = null; - //int x = 0; - sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, " - + "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID " - + "FROM AD_TreeNoDemm A, AD_Menu B " - + "WHERE A.Node_ID = " + menu_id - + " AND A.Node_ID = B.AD_Menu_ID"; - - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - - m_Menu = new X_AD_Menu (getCtx(), rs.getInt("AD_Menu_ID"), null); - atts = createmenuBinding(atts,m_Menu); - hd_menu.startElement("","","menu",atts); - if ( rs.getInt("AD_WINDOW_ID") > 0 || rs.getInt("AD_WORKFLOW_ID") > 0 || rs.getInt("AD_TASK_ID") > 0 || rs.getInt("AD_PROCESS_ID") > 0 || rs.getInt("AD_FORM_ID") > 0 || rs.getInt("AD_WORKBENCH_ID") > 0) - { - //Call CreateWindow. - if (rs.getInt("AD_WINDOW_ID") > 0) - { - CreateWindow (rs.getInt("AD_WINDOW_ID"), atts, hd_menu ); - } - //Call CreateProcess. - else if (rs.getInt("AD_PROCESS_ID") > 0) - { - CreateProcess (rs.getInt("AD_PROCESS_ID"), atts, hd_menu); - } - //Call CreateTask. - else if (rs.getInt("AD_TASK_ID") > 0) - { - CreateTask (rs.getInt("AD_TASK_ID"), atts, hd_menu); - } - //Call CreateForm. - else if (rs.getInt("AD_FORM_ID") > 0) - { - CreateForm (rs.getInt("AD_FORM_ID"), atts, hd_menu); - } - //Call CreateWorkbench - else if (rs.getInt("AD_WORKBENCH_ID") > 0) - { - CreateWorkbench (rs.getInt("AD_WORKBENCH_ID"), atts, hd_menu); - } - //Call CreateWorkflow - else if (rs.getInt("AD_Workflow_ID") > 0) - { - CreateWorkflow(rs.getInt("AD_Workflow_ID"), atts, hd_menu ); - } - //Call CreateModule because entry is a summary menu - } - else - { - CreateModule (atts, hd_menu, rs.getInt("Node_ID")); - } - hd_menu.endElement("","","menu"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - log.log(Level.SEVERE,"getWindows", e); - } - finally - { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; - } + private void initContext() { + Properties tmp = new Properties(); + if (getCtx() != null) + tmp.putAll(getCtx()); + tmp.put("TrxName", get_TrxName()); + tmp.put("PackOutProcess", this); + localContext = tmp; } - - public void CreateModule (AttributesImpl atts, TransformerHandler hd_menu, int menu_id) throws SAXException - { - String sql = null; - sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, " - + "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID " - + "FROM AD_TreeNoDemm A, AD_Menu B " - + "WHERE A.Parent_ID = " + menu_id - + " AND A.Node_ID = B.AD_Menu_ID"; - - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - //Menu tag Start. - m_Menu = new X_AD_Menu (getCtx(), rs.getInt("AD_Menu_ID"), null); - atts = createmenuBinding(atts,m_Menu); - hd_menu.startElement("","","menu",atts); - if ( rs.getInt("AD_WINDOW_ID") > 0 || rs.getInt("AD_WORKFLOW_ID") > 0 || rs.getInt("AD_TASK_ID") > 0 || rs.getInt("AD_PROCESS_ID") > 0 || rs.getInt("AD_FORM_ID") > 0 || rs.getInt("AD_WORKBENCH_ID") > 0) - { - //Call CreateWindow. - if (rs.getInt("AD_WINDOW_ID") > 0) - { - CreateWindow (rs.getInt("AD_WINDOW_ID"), atts, hd_menu ); - } - //Call CreateProcess. - else if (rs.getInt("AD_PROCESS_ID") > 0) - { - CreateProcess (rs.getInt("AD_PROCESS_ID"), atts, hd_menu); - } - //Call CreateTask. - else if (rs.getInt("AD_TASK_ID") > 0) - { - CreateTask (rs.getInt("AD_TASK_ID"), atts, hd_menu); - } - //Call CreateForm. - else if (rs.getInt("AD_FORM_ID") > 0) - { - CreateForm (rs.getInt("AD_FORM_ID"), atts, hd_menu); - } - //Call CreateWorkbench - else if (rs.getInt("AD_WORKBENCH_ID") > 0) - { - CreateWorkbench (rs.getInt("AD_WORKBENCH_ID"), atts, hd_menu); - } - //Call CreateWorkflow - else if (rs.getInt("AD_Workflow_ID") > 0) - { - CreateWorkflow(rs.getInt("AD_Workflow_ID"), atts, hd_menu ); - } - //Call CreateModule because entry is a summary menu - } - else - { - CreateModule (atts, hd_menu, rs.getInt("Node_ID")); - } - hd_menu.endElement("","","menu"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - log.log(Level.SEVERE,"getWindows", e); - } - finally - { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; - } + + + public void createMenu(int AD_Menu_ID, AttributesImpl atts, + TransformerHandler packOutDocument) throws Exception { + Env.setContext(getCtx(), "AD_Menu_ID", AD_Menu_ID); + menuHandler.create(getCtx(), packOutDocument); + getCtx().remove("AD_Menu_ID"); } - - public void CopyCode (String sourceName, String copyName) + + + public void copyCode (String sourceName, String copyName) { - CopyFile (sourceName, copyName ); + copyFile (sourceName, copyName ); } - public void CreatePrintFormat (int AD_PrintFormat_ID, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createPrintFormat (int AD_PrintFormat_ID, AttributesImpl atts, + TransformerHandler packOutDocument) throws Exception { - log.info(""); - String sql = null; - sql = "SELECT AD_PrintFormat_ID " - + "FROM AD_PrintFormat " - + "WHERE AD_PrintFormat_ID in " - + "(( select AD_PrintFormatChild_ID from AD_PrintFormatItem WHERE AD_PrintFormat_ID = " + AD_PrintFormat_ID - + " AND PrintFormatType = 'P'), " + AD_PrintFormat_ID + ")"; - - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - - m_Printformat = new X_AD_PrintFormat (getCtx(), rs.getInt("AD_PrintFormat_ID"), null); - atts = createPrintformatBinding(atts,m_Printformat); - hd_menu.startElement("","","printformat",atts); - - String sql2 = "SELECT * FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID= " + AD_PrintFormat_ID; - PreparedStatement pstmt2 = null; - pstmt2 = DB.prepareStatement (sql2, get_TrxName()); - try { - ResultSet rs2 = pstmt2.executeQuery(); - while (rs2.next()) - { - m_PrintFormatItem = new X_AD_PrintFormatItem (getCtx(), rs2.getInt("AD_PrintFormatItem_ID"), null); - atts = createPrintformatItemBinding(atts,m_PrintFormatItem); - hd_menu.startElement("","","printformatitem",atts); - hd_menu.endElement("","","printformatitem"); - } - rs2.close(); - pstmt2.close(); - pstmt2 = null; - } - - catch (Exception e) - { - log.log(Level.SEVERE,"printformatitem", e); - } - finally - { - try - { - if (pstmt2 != null) - pstmt2.close (); - } - catch (Exception e) - {} - pstmt2 = null; - } - hd_menu.endElement("","","printformat"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - log.log(Level.SEVERE,"getWindows", e); - } - finally - { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; - } - + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID, AD_PrintFormat_ID); + printFormatHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID); } - public void CreateMessage (int AD_Message_ID, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createMessage (int AD_Message_ID, AttributesImpl atts, + TransformerHandler packOutDocument) throws Exception { - log.info(""); - - String sql = "SELECT value FROM AD_Message WHERE AD_Message_ID= " + AD_Message_ID; - - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - - try { - - ResultSet rs = pstmt.executeQuery(); - - while (rs.next()) - { - m_Message = new X_AD_Message (getCtx(), AD_Message_ID, null); - atts = createmessageBinding(atts,m_Message); - hd_menu.startElement("","","message",atts); - hd_menu.endElement("","","message"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e){ - log.log(Level.SEVERE,"getProcess", e); - } - finally{ - try { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e){} - pstmt = null; - } + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID, AD_Message_ID); + messageHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID); } - public void CreateDynamicRuleValidation (int AD_Val_Rule_ID, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createDynamicRuleValidation (int AD_Val_Rule_ID, AttributesImpl atts, + TransformerHandler packOutDocument) throws Exception { - log.info(""); - - String sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID= " + AD_Val_Rule_ID; - - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - - try { - - ResultSet rs = pstmt.executeQuery(); - - while (rs.next()) - { - m_ValRule = new X_AD_Val_Rule (getCtx(), AD_Val_Rule_ID, null); - atts = createdynamicvalidationruleBinding(atts,m_ValRule); - hd_menu.startElement("","","dynvalrule",atts); - hd_menu.endElement("","","dynvalrule"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e){ - log.log(Level.SEVERE,"getProcess", e); - } - finally{ - try { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e){} - pstmt = null; - } + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID, AD_Val_Rule_ID); + dynValRuleHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID); } - public void CreateWorkflow (int AD_Workflow_ID, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createWorkflow (int AD_Workflow_ID, AttributesImpl atts, TransformerHandler packOutDocument) + throws SAXException { - log.info(""); - - String sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID= " + AD_Workflow_ID; - int ad_wf_nodenext_id = 0; - int ad_wf_nodenextcondition_id = 0; - - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - - try { - - ResultSet rs = pstmt.executeQuery(); - - while (rs.next()) - { - m_Workflow = new X_AD_Workflow (getCtx(), AD_Workflow_ID, null); - atts = createworkflowBinding(atts,m_Workflow); - hd_menu.startElement("","","workflow",atts); - String sql1 = "SELECT * FROM AD_WF_Node WHERE AD_Workflow_ID = " + AD_Workflow_ID; - - PreparedStatement pstmt1 = null; - pstmt1 = DB.prepareStatement (sql1, get_TrxName()); - - try { - - ResultSet rs1 = pstmt1.executeQuery(); - - while (rs1.next()){ - - if (rs1.getInt("AD_WF_Node_ID")>0) - m_WF_Node = new X_AD_WF_Node(getCtx(), rs1.getInt("AD_WF_Node_ID"), null); - - atts = createwf_nodeBinding(atts,m_WF_Node); - hd_menu.startElement("","","workflowNode",atts); - hd_menu.endElement("","","workflowNode"); - } - // Generated workflowNodeNext(s) and workflowNodeNextCondition(s) - ResultSet rs2 = pstmt1.executeQuery(); - while (rs2.next()){ - if (rs2.getInt("AD_WF_Node_ID")>0) - - m_WF_Node = new X_AD_WF_Node(getCtx(), rs2.getInt("AD_WF_Node_ID"), null); - ad_wf_nodenext_id = 0; - - sql = "SELECT ad_wf_nodenext_id from ad_wf_nodenext WHERE ad_wf_node_id = ?"; - ad_wf_nodenext_id = DB.getSQLValue(null,sql,m_WF_Node.getAD_WF_Node_ID()); - if (ad_wf_nodenext_id > 0){ - m_WF_NodeNext = new X_AD_WF_NodeNext(getCtx(), ad_wf_nodenext_id, null); - atts = createwf_nodenextBinding(atts,m_WF_NodeNext); - hd_menu.startElement("","","workflowNodeNext",atts); - hd_menu.endElement("","","workflowNodeNext"); - ad_wf_nodenextcondition_id = 0; - - sql = "SELECT ad_wf_nextcondition_id from ad_wf_nextcondition WHERE ad_wf_nodenext_id = ?"; - ad_wf_nodenextcondition_id = DB.getSQLValue(null,sql,m_WF_Node.getAD_WF_Node_ID()); - log.info("ad_wf_nodenextcondition_id: " + String.valueOf(ad_wf_nodenextcondition_id)); - if (ad_wf_nodenextcondition_id > 0){ - m_WF_NodeNextCondition = new X_AD_WF_NextCondition(getCtx(), ad_wf_nodenextcondition_id, null); - atts = createwf_nodenextconditionBinding(atts,m_WF_NodeNextCondition); - hd_menu.startElement("","","workflowNodeNextCondition",atts); - hd_menu.endElement("","","workflowNodeNextCondition"); - } - } - } - - rs2.close(); - rs1.close(); - pstmt1.close(); - pstmt1 = null; - } - catch (Exception e) { - log.log(Level.SEVERE,"getProcess", e); - } - finally { - try { - if (pstmt1 != null) - pstmt1.close (); - } - catch (Exception e){} - pstmt1 = null; - } - hd_menu.endElement("","","workflow"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e){ - log.log(Level.SEVERE,"getProcess", e); - } - finally{ - try { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e){} - pstmt = null; - } - + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID, AD_Workflow_ID); + workflowHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID); } - - - public void CreateWorkbench (int AD_Workbench_ID, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createWorkbench (int AD_Workbench_ID, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - m_Workbench = new X_AD_Workbench (getCtx(), AD_Workbench_ID, null); - atts = createworkbenchBinding(atts,m_Workbench); - hd_menu.startElement("","","workbench",atts); - //Workbenchwindow tags - String sqlP = "SELECT * FROM AD_WorkbenchWindow WHERE AD_WORKBENCH_ID = " + AD_Workbench_ID; - PreparedStatement pstmtP = null; - pstmtP = DB.prepareStatement (sqlP, get_TrxName()); - try { - ResultSet rsP = pstmtP.executeQuery(); - while (rsP.next()) - { - m_Workbenchwindow = new X_AD_WorkbenchWindow (getCtx(), rsP.getInt("AD_Workbench_Window_ID"), null); - atts = createworkbenchwindowBinding(atts,m_Workbenchwindow); - hd_menu.startElement("","","workbenchwindow",atts); - hd_menu.endElement("","","workbenchwindow"); - } - rsP.close(); - pstmtP.close(); - pstmtP = null; - } - catch (Exception e) - { - log.log(Level.SEVERE,"getWorkbench_Window", e); - } - finally - { - try { - if (pstmtP != null) - pstmtP.close (); - } - catch (Exception e) - {} - pstmtP = null; - } - hd_menu.endElement("","","workbench"); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workbench_ID, AD_Workbench_ID); + workbenchHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workbench_ID); } - public void DistributeFile (String FileName, String Source_Directory, String ReleaseNo,String Target_Directory, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createDistributeFile (String FileName, String Source_Directory, String ReleaseNo,String Target_Directory, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - atts.addAttribute("","","name","CDATA",FileName); - atts.addAttribute("","","sourceDirectory","CDATA",Source_Directory); - atts.addAttribute("","","targetDirectory","CDATA",Target_Directory); - atts.addAttribute("","","ReleaseNo","CDATA",ReleaseNo); - hd_menu.startElement("","","distfile",atts); - hd_menu.endElement("","","distfile"); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_FileName, FileName); + Env.setContext(getCtx(), "Source_Directory", Source_Directory); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo, ReleaseNo); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory, Target_Directory); + distFileHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory); + getCtx().remove("Source_Directory"); } - public void CreateForm (int AD_Form_ID, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createForm (int AD_Form_ID, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - m_Form = new X_AD_Form (getCtx(), AD_Form_ID, null); - atts = createformBinding(atts,m_Form); - hd_menu.startElement("","","form",atts); - hd_menu.endElement("","","form"); + Env.setContext(getCtx(), "AD_Form_ID", AD_Form_ID); + formHandler.create(getCtx(), packOutDocument); + getCtx().remove("AD_Form_ID"); } - public void CreateTask (int AD_Task_ID, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createTask (int AD_Task_ID, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - m_Task = new X_AD_Task (getCtx(), AD_Task_ID, null); - atts = createtaskBinding(atts,m_Task); - hd_menu.startElement("","","task",atts); - hd_menu.endElement("","","task"); + Env.setContext(getCtx(), "AD_Task_ID", AD_Task_ID); + taskHandler.create(getCtx(), packOutDocument); + getCtx().remove("AD_Task_ID"); } - public void CreateProcess (int AD_Process_ID, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createProcess (int AD_Process_ID, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - log.log(Level.INFO,"In CreateProcess"); - String sqlW = "SELECT * FROM AD_PROCESS WHERE AD_PROCESS_ID = " + AD_Process_ID; - - PreparedStatement pstmt1 = null; - pstmt1 = DB.prepareStatement (sqlW, get_TrxName()); - try { - ResultSet rs1 = pstmt1.executeQuery(); - while (rs1.next()) - { - X_AD_Process m_Process = new X_AD_Process (getCtx(), rs1.getInt("AD_Process_ID"), null); - log.log(Level.INFO,"AD_ReportView_ID: " + rs1.getInt("AD_ReportView_ID")); - - if (rs1.getString("IsReport").equals('Y') && rs1.getInt("AD_ReportView_ID")>0){ - - CreateReportview(rs1.getInt("AD_ReportView_ID"),atts, hd_menu); - } - if (rs1.getString("IsReport").equals('Y') && rs1.getInt("AD_PrintFormat_ID")>0){ - - CreatePrintFormat(rs1.getInt("AD_PrintFormat_ID"),atts, hd_menu); - } - if (rs1.getInt("AD_Workflow_ID")>0){ - - CreateWorkflow(rs1.getInt("AD_Workflow_ID"),atts, hd_menu); - } - atts = createprocessBinding(atts,m_Process); - hd_menu.startElement("","","process",atts); - // processpara tags - String sqlP = "SELECT * FROM AD_PROCESS_PARA WHERE AD_PROCESS_ID = " + AD_Process_ID; - PreparedStatement pstmtP = null; - pstmtP = DB.prepareStatement (sqlP, get_TrxName()); - try { - ResultSet rsP = pstmtP.executeQuery(); - while (rsP.next()) - { - if (rsP.getInt("AD_Reference_ID")>0) - CreateReference (rsP.getInt("AD_Reference_ID"), atts, hd_menu); - if (rsP.getInt("AD_Reference_Value_ID")>0) - CreateReference (rsP.getInt("AD_Reference_Value_ID"),atts, hd_menu); - m_Processpara = new X_AD_Process_Para (getCtx(), rsP.getInt("AD_Process_Para_ID"), null); - atts = createprocessparaBinding(atts,m_Processpara); - hd_menu.startElement("","","processpara",atts); - hd_menu.endElement("","","processpara"); - } - rsP.close(); - pstmtP.close(); - pstmtP = null; - } - catch (Exception e) - { - log.log(Level.SEVERE,"getProcess_Para", e); - } - finally - { - try { - if (pstmtP != null) - pstmtP.close (); - } - catch (Exception e) - {} - pstmtP = null; - } - /*if(m_Process.getAD_PrintFormat_ID() != 0) { - - m_Printformat = new X_AD_PrintFormat (getCtx(), m_Process.getAD_PrintFormat_ID(), null); - atts = createPrintformatBinding(atts,m_Printformat); - hd_menu.startElement("","","printformat",atts); - - String sql2 = "SELECT * FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID= " + rs1.getInt("AD_Printformat_ID"); - PreparedStatement pstmt2 = null; - pstmt2 = DB.prepareStatement (sql2, get_TrxName()); - try { - ResultSet rs2 = pstmt2.executeQuery(); - while (rs2.next()) - { - m_PrintFormatItem = new X_AD_PrintFormatItem (getCtx(), rs2.getInt("AD_PrintFormatItem_ID"), null); - atts = createPrintformatItemBinding(atts,m_PrintFormatItem); - hd_menu.startElement("","","printformatitem",atts); - hd_menu.endElement("","","printformatitem"); - } - rs2.close(); - pstmt2.close(); - pstmt2 = null; - } - - catch (Exception e) - { - log.log(Level.SEVERE,"printformatitem", e); - } - finally - { - try - { - if (pstmt2 != null) - pstmt2.close (); - } - catch (Exception e) - {} - pstmt2 = null; - } - - hd_menu.endElement("","","printformat"); - }*/ - - hd_menu.endElement("","","process"); - } - rs1.close(); - pstmt1.close(); - pstmt1 = null; - } - catch (Exception e) { - log.log(Level.SEVERE,"getProcess", e); - } - finally{ - try { - if (pstmt1 != null) - pstmt1.close (); - } - catch (Exception e) - {} - pstmt1 = null; - } + Env.setContext(getCtx(), "AD_Process_ID", AD_Process_ID); + processHandler.create(getCtx(), packOutDocument); + getCtx().remove("AD_Process_ID"); } - public void CreateWindow (int AD_Window_ID, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createWindow (int AD_Window_ID, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { -// Window Tag - m_Window = new X_AD_Window (getCtx(), AD_Window_ID, null); - atts = createwindowBinding(atts,m_Window); - hd_menu.startElement("","","window",atts); - //Tab Tag - String sql2 = "SELECT * FROM AD_TAB WHERE AD_WINDOW_ID = " + AD_Window_ID; - PreparedStatement pstmt1 = null; - pstmt1 = DB.prepareStatement (sql2, get_TrxName()); - try { - ResultSet rs1 = pstmt1.executeQuery(); - while (rs1.next()) - { - String sql3 = "SELECT Name FROM AD_Table WHERE AD_Table_ID=?"; - int table_id = rs1.getInt("AD_TABLE_ID"); - String name = rs1.getString("NAME"); - String tablename = DB.getSQLValueString(null, sql3, table_id); - CreateTable (rs1.getInt("AD_Table_ID"), atts, hd_menu); - m_Tab = new X_AD_Tab (getCtx(), rs1.getInt("AD_Tab_ID"), null); - atts = createtabBinding(atts,m_Tab); - hd_menu.startElement("","","tab",atts); - //Fields tags. - String sql4 = "SELECT * FROM AD_FIELD WHERE AD_TAB_ID = " + rs1.getInt("AD_TAB_ID") - + "ORDER BY SEQNO asc"; - PreparedStatement pstmt2 = null; - pstmt2 = DB.prepareStatement (sql4, get_TrxName()); - try { - ResultSet rs2 = pstmt2.executeQuery(); - while (rs2.next()) - { - m_Field = new X_AD_Field (getCtx(), rs2.getInt("AD_Field_ID"), null); - atts = createfieldBinding(atts,m_Field); - hd_menu.startElement("","","field",atts); - hd_menu.endElement("","","field"); - } - rs2.close(); - pstmt2.close(); - pstmt2 = null; - } - catch (Exception e) - { - log.log(Level.SEVERE,"getFields", e); - } - finally - { - try - { - if (pstmt2 != null) - pstmt2.close (); - } - catch (Exception e) - {} - pstmt2 = null; - } - hd_menu.endElement("","","tab"); - } - rs1.close(); - pstmt1.close(); - pstmt1 = null; - } - catch (Exception e) - { - log.log(Level.SEVERE,"getTabs", e); - } - finally - { - try - { - if (pstmt1 != null) - pstmt1.close (); - } - catch (Exception e) - {} - pstmt1 = null; - } - - if(m_Tab.getAD_Process_ID() > 0 ) - { - CreateProcess (m_Tab.getAD_Process_ID(), atts, hd_menu); - } - -// Loop tags. - hd_menu.endElement("","","window"); - - //Preference Tag - sql2 = "SELECT * FROM AD_PREFERENCE WHERE AD_WINDOW_ID = " + AD_Window_ID; - pstmt1 = null; - pstmt1 = DB.prepareStatement (sql2, get_TrxName()); - try { - ResultSet rs1 = pstmt1.executeQuery(); - while (rs1.next()) - { - m_Preference = new X_AD_Preference (getCtx(), rs1.getInt("AD_Preference_ID"), null); - atts = createpreferenceBinding(atts,m_Preference); - hd_menu.startElement("","","preference",atts); - hd_menu.endElement("","","preference"); - } - rs1.close(); - pstmt1.close(); - pstmt1 = null; - } - catch (Exception e) - { - log.log(Level.SEVERE,"getTabs", e); - } - finally - { - try - { - if (pstmt1 != null) - pstmt1.close (); - } - catch (Exception e) - {} - pstmt1 = null; - } - + Env.setContext(getCtx(), "AD_Window_ID", AD_Window_ID); + windowHandler.create(getCtx(), packOutDocument); + getCtx().remove("AD_Window_ID"); } - public void CreateData (int table_id, String sql, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createData (int table_id, String sql, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - Statement stmt = DB.createStatement(); - atts.clear(); - hd_menu.startElement("","","data",atts); - try { - ResultSet rs = stmt.executeQuery(sql); - ResultSetMetaData meta = rs.getMetaData(); - int columns = meta.getColumnCount(); - int i = 1; - String col_Name = null; - String sql1 = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; - String table_Name = DB.getSQLValueString(null,sql1,table_id); - atts.clear(); - atts.addAttribute("","","name","CDATA",table_Name); - hd_menu.startElement("","","dtable",atts); - while (rs.next()){ - atts.clear(); - int key1 = 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 " - + "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; - } - else if (cName.toUpperCase().equals(col_Name) && key1 == 1 ){ - atts.addAttribute("","","key2name","CDATA",cName); - atts.addAttribute("","","lookupkey2name","CDATA",""+rs.getObject(col_Name)); - key1 = 2; - } - } - } - atts.addAttribute("","","name","CDATA",nameatts); - if ( key1 == 0 ){ - atts.addAttribute("","","key1name","CDATA",""); - atts.addAttribute("","","lookupkey1name","CDATA",""); - key1 = 1; - } - if ( key1 == 1 ){ - atts.addAttribute("","","key2name","CDATA",""); - atts.addAttribute("","","lookupkey2name","CDATA",""); - } - hd_menu.startElement("","","drow",atts); - for (i=1 ;i <= columns;i++){ - atts.clear(); - col_Name = meta.getColumnName(i).toUpperCase(); - String sql2 = "Select A.ColumnName, B.Name " - + "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"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql2, get_TrxName()); - pstmt.setString(1, col_Name); - pstmt.setInt(2, table_id); - ResultSet rs1 = pstmt.executeQuery(); - while (rs1.next()){ - //added 9/3/05 - 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)); - - if (!rs1.getString("ColumnName").equals("Created")&&!rs1.getString("ColumnName").equals("CreatedBy")&& - !rs1.getString("ColumnName").equals("Updated")&&!rs1.getString("ColumnName").equals("UpdatedBy")){ - hd_menu.startElement("","","dcolumn",atts); - hd_menu.endElement("","","dcolumn"); - } - } - rs1.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.log(Level.SEVERE,"getData", e); - } - } - hd_menu.endElement("","","drow"); - } - rs.close(); - stmt.close(); - stmt = null; - hd_menu.endElement("","","dtable"); - } - - catch (Exception e) { - log.log(Level.SEVERE,"getData", e); - } - - hd_menu.endElement("","","data"); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID, table_id); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement, sql); + dataHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); } - public void CreateReportview (int Reportview_id, AttributesImpl atts, TransformerHandler hd_menu) + public void createReportview (int Reportview_id, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - String sql = "SELECT * FROM AD_ReportView WHERE AD_ReportView_ID= " + Reportview_id; - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - atts.clear(); - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - m_Reportview = new X_AD_ReportView (getCtx(), rs.getInt("AD_Reportview_ID"), null); - atts = createreportviewBinding(atts,m_Reportview); - hd_menu.startElement("","","reportview",atts); - hd_menu.endElement("","","reportview"); - - String sql1 = "SELECT * FROM AD_Printformat WHERE AD_Reportview_ID= " + Reportview_id; - PreparedStatement pstmt1 = null; - pstmt1 = DB.prepareStatement (sql1, get_TrxName()); - try { - ResultSet rs1 = pstmt1.executeQuery(); - while (rs1.next()) - { - //Export Table if neccessary - CreateTable (rs1.getInt("AD_Table_ID"), atts, hd_menu); - - m_Printformat = new X_AD_PrintFormat (getCtx(), rs1.getInt("AD_Printformat_ID"), null); - atts = createPrintformatBinding(atts,m_Printformat); - hd_menu.startElement("","","printformat",atts); - - String sql2 = "SELECT * FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID= " + rs1.getInt("AD_Printformat_ID"); - PreparedStatement pstmt2 = null; - pstmt2 = DB.prepareStatement (sql2, get_TrxName()); - try { - ResultSet rs2 = pstmt2.executeQuery(); - while (rs2.next()) - { - m_PrintFormatItem = new X_AD_PrintFormatItem (getCtx(), rs2.getInt("AD_PrintFormatItem_ID"), null); - atts = createPrintformatItemBinding(atts,m_PrintFormatItem); - hd_menu.startElement("","","printformatitem",atts); - hd_menu.endElement("","","printformatitem"); - } - rs2.close(); - pstmt2.close(); - pstmt2 = null; - } - - catch (Exception e) - { - log.log(Level.SEVERE,"printformatitem", e); - } - finally - { - try - { - if (pstmt2 != null) - pstmt2.close (); - } - catch (Exception e) - {} - pstmt2 = null; - } - - - hd_menu.endElement("","","printformat"); - } - rs1.close(); - pstmt1.close(); - pstmt1 = null; - } - - catch (Exception e) - { - log.log(Level.SEVERE,"printformat", e); - } - finally - { - try - { - if (pstmt1 != null) - pstmt1.close (); - } - catch (Exception e) - {} - pstmt1 = null; - } - atts.clear(); - sql1 = "SELECT * FROM AD_ReportView_Col WHERE AD_Reportview_ID= " + Reportview_id; - pstmt1 = null; - pstmt1 = DB.prepareStatement (sql1, get_TrxName()); - try { - ResultSet rs1 = pstmt1.executeQuery(); - while (rs1.next()) - { - m_Reportview_Col = new X_AD_ReportView_Col (getCtx(), rs1.getInt("AD_ReportView_Col_ID"), null); - atts = createreportviewcolBinding(atts,m_Reportview_Col); - hd_menu.startElement("","","reportviewcol",atts); - hd_menu.endElement("","","reportviewcol"); - } - rs1.close(); - pstmt1.close(); - pstmt1 = null; - } - - catch (Exception e) - { - log.log(Level.SEVERE,"reportviewcol", e); - } - finally - { - try - { - if (pstmt1 != null) - pstmt1.close (); - } - catch (Exception e) - {} - pstmt1 = null; - } - //atts = createreportviewBinding(atts,m_Reportview); - //hd_menu.startElement("","","reportview",atts); - //hd_menu.endElement("","","reportview"); - } - - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e) - { - log.log(Level.SEVERE,"reportview", e); - } - - - finally - { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; - } + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID, Reportview_id); + reportViewHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID); } - public void CreateSQL (String SQLStatement, String DBType,AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createSQL (String SQLStatement, String DBType,AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - atts = createSQLStatmentBinding(atts, SQLStatement, DBType); - hd_menu.startElement("","","SQLStatement",atts); - hd_menu.endElement("","","SQLStatement"); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement, SQLStatement); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_DBType, DBType); + sqlHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_DBType); } - public void CreateSnipit (String FileDir, String FileName, String OldCode, String NewCode, String ReleaseNo, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createSnipit (String FileDir, String FileName, String OldCode, String NewCode, String ReleaseNo, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - atts = createSnipitBinding(atts, FileDir, FileName, OldCode, NewCode, ReleaseNo); - hd_menu.startElement("","","codesnipit",atts); - hd_menu.endElement("","","codesnipit"); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory, FileDir); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_FileName, FileName); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old, OldCode); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New, NewCode); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo, ReleaseNo); + codeHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); } - public void CreateRoles (int Role_id, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createRoles (int Role_id, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - - - //Process role - m_Role = new X_AD_Role (getCtx(), Role_id, null); - atts = createroleBinding(atts,m_Role); - hd_menu.startElement("","","role",atts); - - //Process org access - String sql = "SELECT * FROM AD_Role_OrgAccess WHERE AD_Role_ID= " + Role_id; - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - atts = createorgaccessBinding(atts,rs.getInt("AD_Org_ID"),rs.getInt("AD_Role_ID")); - hd_menu.startElement("","","OrgAccess",atts); - hd_menu.endElement("","","OrgAccess"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e) { - log.log(Level.SEVERE,"CreateRoles-Window Access", e); - } - //Process user assignment access - sql = "SELECT * FROM AD_User_Roles WHERE AD_Role_ID= " + Role_id; - pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - atts = createusrassignBinding(atts,rs.getInt("AD_User_ID"),rs.getInt("AD_Role_ID"),rs.getInt("AD_Org_ID")); - hd_menu.startElement("","","userrole",atts); - hd_menu.endElement("","","userrole"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e) { - log.log(Level.SEVERE,"CreateRoles-Window Access", e); - } - //Process AD_Window_Access Values - sql = "SELECT * FROM AD_Window_Access WHERE AD_Role_ID= " + Role_id; - pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - atts = createwindowaccessBinding(atts,rs.getInt("AD_Window_ID"),rs.getInt("AD_Role_ID")); - hd_menu.startElement("","","windowaccess",atts); - hd_menu.endElement("","","windowaccess"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e) { - log.log(Level.SEVERE,"CreateRoles-Window Access", e); - } - -// Process AD_Process_Access Values - sql = "SELECT * FROM AD_Process_Access WHERE AD_Role_ID= " + Role_id; - pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - //m_Process_Access = new X_AD_Process_Access (getCtx(), rs.getInt("AD_Process_ID"), null); - atts = createprocessaccessBinding(atts,rs.getInt("AD_Process_ID"),rs.getInt("AD_Role_ID")); - hd_menu.startElement("","","processaccess",atts); - hd_menu.endElement("","","processaccess"); - - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e) { - log.log(Level.SEVERE,"CreateRoles-AD_Process", e); - } - -// Process AD_Form_Access Values - sql = "SELECT * FROM AD_Form_Access WHERE AD_Role_ID= " + Role_id; - pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - //m_Form_Access = new X_AD_Form_Access (getCtx(), rs.getInt("AD_Form_ID"), null); - atts = createformaccessBinding(atts,rs.getInt("AD_Form_ID"),rs.getInt("AD_Role_ID")); - hd_menu.startElement("","","formaccess",atts); - hd_menu.endElement("","","formaccess"); - - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e) { - log.log(Level.SEVERE,"CreateRoles-Form Access", e); - } - -// Process AD_Workflow_Access Values - sql = "SELECT * FROM AD_Workflow_Access WHERE AD_Role_ID= " + Role_id; - pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - //m_Workflow_Access = new X_AD_Workflow_Access (getCtx(), rs.getInt("AD_Workflow_ID"), null); - atts = createworkflowaccessBinding(atts,rs.getInt("AD_Workflow_ID"),rs.getInt("AD_Role_ID")); - hd_menu.startElement("","","workflowaccess",atts); - hd_menu.endElement("","","workflowaccess"); - - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e) { - log.log(Level.SEVERE,"CreateRoles-Workflow", e); - } - -// Process AD_Task_Access Values - sql = "SELECT * FROM AD_Task_Access WHERE AD_Role_ID= " + Role_id; - pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - //m_Task_Access = new X_AD_Task_Access (getCtx(), rs.getInt("AD_Task_ID"), null); - atts = createtaskaccessBinding(atts,rs.getInt("AD_Task_ID"),rs.getInt("AD_Role_ID")); - hd_menu.startElement("","","taskaccess",atts); - hd_menu.endElement("","","taskaccess"); - - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e) { - log.log(Level.SEVERE,"CreateRoles-Task", e); - } - finally - { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; - } - hd_menu.endElement("","","role"); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID, Role_id); + roleHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID); } - public void CreateReference (int Reference_id, AttributesImpl atts, TransformerHandler hd_menu) + public void createReference (int Reference_id, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - String sql = "SELECT * FROM AD_Reference WHERE AD_Reference_ID= " + Reference_id; - - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - - try { - - ResultSet rs = pstmt.executeQuery(); - - while (rs.next()) - { - - m_Reference = new X_AD_Reference (getCtx(), rs.getInt("AD_Reference_ID"), null); - atts = createreferenceBinding(atts,m_Reference); - hd_menu.startElement("","","reference",atts); - - - if (m_Reference.getValidationType().compareTo("L")== 0) - { - String sql1 = "SELECT * FROM AD_Ref_List WHERE AD_Reference_ID= " + Reference_id; - - PreparedStatement pstmt1 = null; - pstmt1 = DB.prepareStatement (sql1, get_TrxName()); - - try { - - ResultSet rs1 = pstmt1.executeQuery(); - - while (rs1.next()) - { - - m_Ref_List = new X_AD_Ref_List (getCtx(), rs1.getInt("AD_REF_LIST_ID"), null); - atts = createreflistBinding(atts,m_Ref_List); - hd_menu.startElement("","","referencelist",atts); - hd_menu.endElement("","","referencelist"); - } - rs1.close(); - pstmt1.close(); - pstmt1 = null; - } - - catch (Exception e) - { - log.log(Level.SEVERE,"getRef_List", e); - } - - - finally - { - try - { - if (pstmt1 != null) - pstmt1.close (); - } - catch (Exception e) - {} - pstmt1 = null; - } - - } - else if (m_Reference.getValidationType().compareTo("T")== 0) - { - String sql1 = "SELECT * FROM AD_Reference WHERE AD_Reference_ID= " + Reference_id; - PreparedStatement pstmt1 = null; - pstmt1 = DB.prepareStatement (sql1, get_TrxName()); - - try { - - ResultSet rs1 = pstmt1.executeQuery(); - - while (rs1.next()) - { - atts = createreferencetableBinding(atts,Reference_id); - hd_menu.startElement("","","referencetable",atts); - hd_menu.endElement("","","referencetable"); - } - rs1.close(); - pstmt1.close(); - pstmt1 = null; - } - - catch (Exception e) - { - log.log(Level.SEVERE,"getRef_Table", e); - } - - - finally - { - try - { - if (pstmt1 != null) - pstmt1.close (); - } - catch (Exception e) - {} - pstmt1 = null; - } - } - hd_menu.endElement("","","reference"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e) - { - log.log(Level.SEVERE,"getRefence", e); - } - - - finally - { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; - } + Env.setContext(getCtx(), X_AD_Reference.COLUMNNAME_AD_Reference_ID, Reference_id); + referenceHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Reference.COLUMNNAME_AD_Reference_ID); } - public void CreateImp (int import_id, AttributesImpl atts, TransformerHandler hd_menu) throws SAXException + public void createImpFormat (int import_id, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - atts.clear(); - m_ImpFormat = new X_AD_ImpFormat (getCtx(), import_id, null); - atts = createimpBinding(atts,m_ImpFormat); - - hd_menu.startElement("","","impformat",atts); - String sql = "SELECT * FROM AD_ImpFormat_Row WHERE AD_ImpFormat_ID= " + import_id; - - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - m_ImpFormat_Row = new X_AD_ImpFormat_Row (getCtx(), rs.getInt("AD_ImpFormat_Row_ID"), null); - atts = createimprowBinding(atts,m_ImpFormat_Row); - hd_menu.startElement("","","impformatrow",atts); - hd_menu.endElement("","","impformatrow"); - - } - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.log(Level.SEVERE,"getProcess", e); - } - finally { - try { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e){} - pstmt = null; - } - hd_menu.endElement("","","impformat"); + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID, import_id); + impFormtHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID); } - public void CreateTable (int table_id, AttributesImpl atts, TransformerHandler hd_menu) + public void createTable (int table_id, AttributesImpl atts, TransformerHandler packOutDocument) throws SAXException { - int New_Table = 2; - - // check to see if table has been exported already - if (Table_Count == 0){ - Table_ID[Table_Count] = table_id; - Table_Count = Table_Count+1; - New_Table = 1; - } - else{ - int i; - for(i=0;i0) - CreateReference (rs1.getInt("AD_Reference_ID"), atts, hd_menu); - - if (rs1.getInt("AD_Reference_Value_ID")>0) - CreateReference (rs1.getInt("AD_Reference_Value_ID"), atts, hd_menu); - - if (rs1.getInt("AD_Process_ID")>0) - CreateProcess (rs1.getInt("AD_Process_ID"), atts, hd_menu); - - if (rs1.getInt("AD_Val_Rule_ID")>0) - CreateDynamicRuleValidation (rs1.getInt("AD_Val_Rule_ID"), atts, hd_menu); - - m_Column = new X_AD_Column (getCtx(), rs1.getInt("AD_Column_ID"), null); - atts = createcolumnBinding(atts,m_Column); - hd_menu.startElement("","","column",atts); - hd_menu.endElement("","","column"); - } - - rs1.close(); - pstmt1.close(); - pstmt1 = null; - } - catch (Exception e) { - log.log(Level.SEVERE,"getProcess", e); - } - finally { - try { - if (pstmt1 != null) - pstmt1.close (); - } - catch (Exception e){} - pstmt1 = null; - } - hd_menu.endElement("","","table"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - - catch (Exception e){ - log.log(Level.SEVERE,"getProcess", e); - } - finally{ - try { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e){} - pstmt = null; - } - } + Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID, table_id); + tableHandler.create(getCtx(), packOutDocument); + getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID); } - public static 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():"")); - return atts; - } - - public static AttributesImpl createpreferenceBinding( AttributesImpl atts, X_AD_Preference m_Preference) - { - String sql = null; - String name = null; - atts.clear(); - sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; - name = DB.getSQLValueString(null,sql,m_Preference.getAD_Window_ID()); - atts.addAttribute("","","ADWindowNameID","CDATA",name); - sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?"; - name = DB.getSQLValueString(null,sql,m_Preference.getAD_User_ID()); - atts.addAttribute("","","ADUserNameID","CDATA",name); - atts.addAttribute("","","Attribute","CDATA",m_Preference.getAttribute()); - atts.addAttribute("","","Value","CDATA",m_Preference.getValue()); - return atts; - } - - public static AttributesImpl createtabBinding( AttributesImpl atts, X_AD_Tab m_Tab) - { - String sql = null; - String name = null; - atts.clear(); - atts.addAttribute("","","Name","CDATA",(m_Tab.getName () != null ? m_Tab.getName ():"")); - if (m_Tab.getAD_ColumnSortOrder_ID()>0){ - sql = "SELECT Name FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,m_Tab.getAD_ColumnSortOrder_ID()); - atts.addAttribute("","","ADColumnSortOrderNameID","CDATA",name); - } - else - atts.addAttribute("","","ADColumnSortOrderNameID","CDATA",""); - if (m_Tab.getAD_ColumnSortYesNo_ID()>0 ){ - sql = "SELECT Name FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,m_Tab.getAD_ColumnSortYesNo_ID()); - atts.addAttribute("","","ADColumnSortYesNoNameID","CDATA",name); - } - else - atts.addAttribute("","","ADColumnSortYesNoNameID","CDATA",""); - if (m_Tab.getAD_Column_ID()>0 ){ - sql = "SELECT Name FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,m_Tab.getAD_Column_ID()); - atts.addAttribute("","","ADColumnNameID","CDATA",name); - } - else - atts.addAttribute("","","ADColumnNameID","CDATA",""); - if (m_Tab.getAD_Image_ID() >0 ){ - sql = "SELECT Name FROM AD_Image WHERE AD_Image_ID=?"; - name = DB.getSQLValueString(null,sql,m_Tab.getAD_Image_ID()); - atts.addAttribute("","","ADImageNameID","CDATA",name); - } - else - atts.addAttribute("","","ADImageNameID","CDATA",""); - if (m_Tab.getAD_Process_ID() >0 ){ - sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; - name = DB.getSQLValueString(null,sql,m_Tab.getAD_Process_ID()); - atts.addAttribute("","","ADProcessNameID","CDATA",name); - } - else - atts.addAttribute("","","ADProcessNameID","CDATA",""); - if (m_Tab.getAD_Tab_ID() >0 ){ - sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?"; - name = DB.getSQLValueString(null,sql,m_Tab.getAD_Tab_ID()); - atts.addAttribute("","","ADTabNameID","CDATA",name); - } - else - atts.addAttribute("","","ADTabNameID","CDATA",""); - - sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; - name = DB.getSQLValueString(null,sql,m_Tab.getAD_Table_ID()); - atts.addAttribute("","","ADTableNameID","CDATA",name); - sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; - name = DB.getSQLValueString(null,sql,m_Tab.getAD_Window_ID()); - atts.addAttribute("","","ADWindowNameID","CDATA",name); - if (m_Tab.getIncluded_Tab_ID() > 0 ){ - sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?"; - name = DB.getSQLValueString(null,sql,m_Tab.getIncluded_Tab_ID()); - atts.addAttribute("","","IncludedTabNameID","CDATA",name); - } - else - atts.addAttribute("","","IncludedTabNameID","CDATA",""); - atts.addAttribute("","","CommitWarning","CDATA",(m_Tab.getCommitWarning () != null ? m_Tab.getCommitWarning ():"")); - atts.addAttribute("","","Description","CDATA",(m_Tab.getDescription () != null ? m_Tab.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Tab.getEntityType () != null ? m_Tab.getEntityType ():"")); - atts.addAttribute("","","isHasTree","CDATA",(m_Tab.isHasTree()== true ? "true":"false")); - atts.addAttribute("","","Help","CDATA",(m_Tab.getHelp () != null ? m_Tab.getHelp ():"")); - atts.addAttribute("","","isInfoTab","CDATA",(m_Tab.isInfoTab()== true ? "true":"false")); - atts.addAttribute("","","isReadOnly","CDATA",(m_Tab.isReadOnly()== true ? "true":"false")); - atts.addAttribute("","","isSingleRow","CDATA",(m_Tab.isSingleRow()== true ? "true":"false")); - atts.addAttribute("","","isSortTab","CDATA",(m_Tab.isSortTab()== true ? "true":"false")); - atts.addAttribute("","","isActive","CDATA",(m_Tab.isActive()== true ? "true":"false")); - atts.addAttribute("","","IsTranslationTab","CDATA",(m_Tab.isTranslationTab()== true ? "true":"false")); - atts.addAttribute("","","OrderByClause","CDATA",(m_Tab.getOrderByClause () != null ? m_Tab.getOrderByClause ():"")); - atts.addAttribute("","","isProcessing","CDATA",(m_Tab.isProcessing()== true ? "true":"false")); - atts.addAttribute("","","SeqNo","CDATA",(m_Tab.getSeqNo () >= 0 ? "" + m_Tab.getSeqNo ():"0")); - atts.addAttribute("","","TabLevel","CDATA",(m_Tab.getTabLevel () >= 0 ? "" + m_Tab.getTabLevel ():"")); - atts.addAttribute("","","WhereClause","CDATA",(m_Tab.getWhereClause () != null ? m_Tab.getWhereClause ():"")); - atts.addAttribute("","","ReadOnlyLogic","CDATA",(m_Tab.getReadOnlyLogic() != null ? m_Tab.getReadOnlyLogic ():"")); - atts.addAttribute("","","DisplayLogic","CDATA",(m_Tab.getDisplayLogic() != null ? m_Tab.getDisplayLogic ():"")); - atts.addAttribute("","","isInsertRecord","CDATA",(m_Tab.isInsertRecord()== true ? "true":"false")); - atts.addAttribute("","","isAdvancedTab","CDATA",(m_Tab.isAdvancedTab()== true ? "true":"false")); - atts.addAttribute("","","Syncfields","CDATA","false"); - return atts; - } - - public static AttributesImpl createwindowBinding( AttributesImpl atts, X_AD_Window m_Window) - { - atts.clear(); - String sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; - String name = DB.getSQLValueString(null,sql,m_Window.getAD_Window_ID()); - atts.addAttribute("","","ADWindowNameID","CDATA",name); - if (m_Window.getAD_Image_ID()> 0 ){ - sql = "SELECT Name FROM AD_Image WHERE AD_Image_ID=?"; - name = DB.getSQLValueString(null,sql,m_Window.getAD_Image_ID()); - } - if (name != null ) - atts.addAttribute("","","ADImageNameID","CDATA",name); - else - atts.addAttribute("","","ADImageNameID","CDATA",""); - if (m_Window.getAD_Color_ID()> 0 ){ - sql = "SELECT Name FROM AD_Color WHERE AD_Color_ID=?"; - name = DB.getSQLValueString(null,sql,m_Window.getAD_Color_ID()); - } - if (name != null ) - atts.addAttribute("","","ADColorNameID","CDATA",name); - else - atts.addAttribute("","","ADColorNameID","CDATA",""); - atts.addAttribute("","","Description","CDATA",(m_Window.getDescription () != null ? m_Window.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Window.getEntityType () != null ? m_Window.getEntityType ():"")); - atts.addAttribute("","","Help","CDATA",(m_Window.getHelp () != null ? m_Window.getHelp ():"")); - atts.addAttribute("","","isBetaFunctionality","CDATA",(m_Window.isBetaFunctionality()== true ? "true":"false")); - atts.addAttribute("","","isDefault","CDATA",(m_Window.isDefault()== true ? "true":"false")); - atts.addAttribute("","","isSOTrx","CDATA",(m_Window.isSOTrx()== true ? "true":"false")); - atts.addAttribute("","","isActive","CDATA",(m_Window.isActive()== true ? "true":"false")); - atts.addAttribute("","","Name","CDATA",(m_Window.getName () != null ? m_Window.getName ():"")); - atts.addAttribute("","","isProcessing","CDATA",(m_Window.isProcessing()== true ? "true":"false")); - atts.addAttribute("","","WinHeight","CDATA",(m_Window.getWinHeight () > 0 ? "" + m_Window.getWinHeight ():"")); - atts.addAttribute("","","WinWidth","CDATA",(m_Window.getWinWidth () > 0 ? "" + m_Window.getWinWidth ():"")); - atts.addAttribute("","","WindowType","CDATA",(m_Window.getWindowType () != null ? m_Window.getWindowType ():"")); - return atts; - } - - public static AttributesImpl createmenuBinding( AttributesImpl atts, X_AD_Menu m_Menu) - { - String sql = null; - String name = null; - atts.clear(); - if (m_Menu.getAD_Menu_ID()> 0 ){ - - sql = "SELECT Name FROM AD_Menu WHERE AD_Menu_ID=?"; - name = DB.getSQLValueString(null,sql,m_Menu.getAD_Menu_ID()); - atts.addAttribute("","","ADMenuNameID","CDATA",name); - } - else - atts.addAttribute("","","ADMenuNameID","CDATA",""); - if (m_Menu.getAD_Window_ID()> 0 ){ - sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; - name = DB.getSQLValueString(null,sql,m_Menu.getAD_Window_ID()); - atts.addAttribute("","","ADWindowNameID","CDATA",name); - } - else - atts.addAttribute("","","ADWindowNameID","CDATA",""); - if (m_Menu.getAD_Process_ID()> 0 ){ - sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; - name = DB.getSQLValueString(null,sql,m_Menu.getAD_Process_ID()); - atts.addAttribute("","","ADProcessNameID","CDATA",name); - } - else - atts.addAttribute("","","ADProcessNameID","CDATA",""); - if (m_Menu.getAD_Form_ID()> 0 ){ - sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?"; - name = DB.getSQLValueString(null,sql,m_Menu.getAD_Form_ID()); - atts.addAttribute("","","ADFormNameID","CDATA",name); - } - else - atts.addAttribute("","","ADFormNameID","CDATA",""); - if (m_Menu.getAD_Task_ID()> 0 ){ - sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?"; - name = DB.getSQLValueString(null,sql,m_Menu.getAD_Task_ID()); - atts.addAttribute("","","ADTaskNameID","CDATA",name); - } - else - atts.addAttribute("","","ADTaskNameID","CDATA",""); - if (m_Menu.getAD_Workbench_ID()> 0 ){ - sql = "SELECT Name FROM AD_Workbench WHERE AD_Workbench_ID=?"; - name = DB.getSQLValueString(null,sql,m_Menu.getAD_Workbench_ID()); - atts.addAttribute("","","ADWorkbenchNameID","CDATA",name); - } - else - atts.addAttribute("","","ADWorkbenchNameID","CDATA",""); - if (m_Menu.getAD_Workflow_ID()> 0 ){ - sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?"; - name = DB.getSQLValueString(null,sql,m_Menu.getAD_Workflow_ID()); - atts.addAttribute("","","ADWorkflowNameID","CDATA",name); - } - else - atts.addAttribute("","","ADWorkflowNameID","CDATA",""); - sql = "SELECT Parent_ID FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?"; - int id = DB.getSQLValue(null, sql,m_Menu.getAD_Menu_ID()); - if (id > 0){ - sql = "SELECT Name FROM AD_Menu WHERE AD_Menu_ID=?"; - name = DB.getSQLValueString(null,sql,id); - atts.addAttribute("","","ADParentMenuNameID","CDATA",name); - } - sql = "SELECT SeqNo FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?"; - id = DB.getSQLValue(null, sql,m_Menu.getAD_Menu_ID()); - atts.addAttribute("","","ADParentSeqno","CDATA",""+id); - atts.addAttribute("","","Action","CDATA",(m_Menu.getAction () != null ? m_Menu.getAction ():"")); - atts.addAttribute("","","Description","CDATA",(m_Menu.getDescription () != null ? m_Menu.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Menu.getEntityType () != null ? m_Menu.getEntityType ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Menu.isActive()== true ? "true":"false")); - atts.addAttribute("","","isReadOnly","CDATA",(m_Menu.isReadOnly()== true ? "true":"false")); - atts.addAttribute("","","isSOTrx","CDATA",(m_Menu.isSOTrx()== true ? "true":"false")); - atts.addAttribute("","","isSummary","CDATA",(m_Menu.isSummary()== true ? "true":"false")); - return atts; - } - - public static AttributesImpl createprocessBinding( AttributesImpl atts, X_AD_Process m_Process) - { - String sql = null; - String name = null; - atts.clear(); - - atts.addAttribute("","","Name","CDATA",(m_Process.getName () != null ? m_Process.getName ():"")); - - if (m_Process.getAD_Workflow_ID()> 0 ){ - sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?"; - name = DB.getSQLValueString(null,sql,m_Process.getAD_Workflow_ID()); - atts.addAttribute("","","ADWorkflowNameID","CDATA",name); - } - else - atts.addAttribute("","","ADWorkflowNameID","CDATA",""); - if (m_Process.getAD_Process_ID()> 0 ){ - sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; - name = DB.getSQLValueString(null,sql,m_Process.getAD_Process_ID()); - atts.addAttribute("","","ADProcessNameID","CDATA",name); - } - else - atts.addAttribute("","","ADProcessNameID","CDATA",""); - if (m_Process.getAD_PrintFormat_ID()> 0 ){ - sql = "SELECT Name FROM AD_PrintFormat WHERE AD_PrintFormat_ID=?"; - name = DB.getSQLValueString(null,sql,m_Process.getAD_PrintFormat_ID()); - atts.addAttribute("","","ADPrintFormatNameID","CDATA",name); - } - else - atts.addAttribute("","","ADPrintFormatNameID","CDATA",""); - if (m_Process.getAD_ReportView_ID()> 0 ){ - sql = "SELECT Name FROM AD_ReportView WHERE AD_ReportView_ID=?"; - name = DB.getSQLValueString(null,sql,m_Process.getAD_ReportView_ID()); - atts.addAttribute("","","ADReportViewNameID","CDATA",name); - } - else - atts.addAttribute("","","ADReportViewNameID","CDATA",""); - atts.addAttribute("","","AccessLevel","CDATA",(m_Process.getAccessLevel () != null ? m_Process.getAccessLevel ():"")); - atts.addAttribute("","","Classname","CDATA",(m_Process.getClassname () != null ? m_Process.getClassname ():"")); - atts.addAttribute("","","Description","CDATA",(m_Process.getDescription () != null ? m_Process.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Process.getEntityType () != null ? m_Process.getEntityType ():"")); - atts.addAttribute("","","Help","CDATA",(m_Process.getHelp () != null ? m_Process.getHelp ():"")); - atts.addAttribute("","","isBetaFunctionality","CDATA",(m_Process.isBetaFunctionality()== true ? "true":"false")); - atts.addAttribute("","","isDirectPrint","CDATA",(m_Process.isDirectPrint()== true ? "true":"false")); - atts.addAttribute("","","isReport","CDATA",(m_Process.isReport()== true ? "true":"false")); - atts.addAttribute("","","isActive","CDATA",(m_Process.isActive()== true ? "true":"false")); - atts.addAttribute("","","ProcedureName","CDATA",(m_Process.getProcedureName () != null ? m_Process.getProcedureName ():"")); - atts.addAttribute("","","StatisticCount","CDATA","0"); - atts.addAttribute("","","StatisticSeconds","CDATA","0"); - atts.addAttribute("","","Value","CDATA",(m_Process.getValue () != null ? m_Process.getValue ():"")); - atts.addAttribute("","","WorkflowValue","CDATA",(m_Process.getWorkflowValue () != null ? m_Process.getWorkflowValue ():"")); - return atts; - } - - public static AttributesImpl createprocessparaBinding( AttributesImpl atts, X_AD_Process_Para m_Processpara) - { - String sql = null; - String name = null; - atts.clear(); - atts.addAttribute("","","Name","CDATA",(m_Processpara.getName () != null ? m_Processpara.getName ():"")); - if (m_Processpara.getAD_Process_ID()> 0 ){ - sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; - name = DB.getSQLValueString(null,sql,m_Processpara.getAD_Process_ID()); - atts.addAttribute("","","ADProcessNameID","CDATA",name); - } - else - atts.addAttribute("","","ADProcessNameID","CDATA",""); - if (m_Processpara.getAD_Process_Para_ID()> 0 ){ - sql = "SELECT Name FROM AD_Process_Para WHERE AD_Process_Para_ID=?"; - name = DB.getSQLValueString(null,sql,m_Processpara.getAD_Process_Para_ID()); - atts.addAttribute("","","ADProcessParaNameID","CDATA",name); - } - else - atts.addAttribute("","","ADProcessParaNameID","CDATA",""); - if (m_Processpara.getAD_Element_ID()> 0 ){ - sql = "SELECT Name FROM AD_Element WHERE AD_Element_ID=?"; - name = DB.getSQLValueString(null,sql,m_Processpara.getAD_Element_ID()); - atts.addAttribute("","","ADElementNameID","CDATA",name); - } - else - atts.addAttribute("","","ADElementNameID","CDATA",""); - if (m_Processpara.getAD_Reference_ID()> 0 ){ - sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; - name = DB.getSQLValueString(null,sql,m_Processpara.getAD_Reference_ID()); - atts.addAttribute("","","ADReferenceNameID","CDATA",name); - } - else - atts.addAttribute("","","ADReferenceNameID","CDATA",""); - if (m_Processpara.getAD_Reference_Value_ID()> 0 ){ - sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; - name = DB.getSQLValueString(null,sql,m_Processpara.getAD_Reference_Value_ID()); - atts.addAttribute("","","ADReferenceValueNameID","CDATA",name); - } - else - atts.addAttribute("","","ADReferenceValueNameID","CDATA",""); - if (m_Processpara.getAD_Val_Rule_ID()> 0 ){ - sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?"; - name = DB.getSQLValueString(null,sql,m_Processpara.getAD_Val_Rule_ID()); - atts.addAttribute("","","ADValRuleNameID","CDATA",name); - } - else - atts.addAttribute("","","ADValRuleNameID","CDATA",""); - atts.addAttribute("","","ColumnName","CDATA",(m_Processpara.getColumnName () != null ? m_Processpara.getColumnName ():"")); - atts.addAttribute("","","DefaultValue","CDATA",(m_Processpara.getDefaultValue () != null ? m_Processpara.getDefaultValue ():"")); - atts.addAttribute("","","DefaultValue2","CDATA",(m_Processpara.getDefaultValue2 () != null ? m_Processpara.getDefaultValue2 ():"")); - atts.addAttribute("","","Description","CDATA",(m_Processpara.getDescription () != null ? m_Processpara.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Processpara.getEntityType () != null ? m_Processpara.getEntityType ():"")); - atts.addAttribute("","","Help","CDATA",(m_Processpara.getHelp () != null ? m_Processpara.getHelp ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Processpara.isActive()== true ? "true":"false")); - atts.addAttribute("","","VFormat","CDATA",(m_Processpara.getVFormat () != null ? m_Processpara.getVFormat ():"")); - atts.addAttribute("","","ValueMax","CDATA",(m_Processpara.getValueMax () != null ? m_Processpara.getValueMax ():"")); - atts.addAttribute("","","ValueMin","CDATA",(m_Processpara.getValueMin () != null ? m_Processpara.getValueMin ():"")); - atts.addAttribute("","","SeqNo","CDATA",(m_Processpara.getSeqNo() > 0 ? "" + m_Processpara.getSeqNo ():"0")); - atts.addAttribute("","","FieldLength","CDATA",(m_Processpara.getFieldLength () > 0 ? "" + m_Processpara.getFieldLength ():"0")); - atts.addAttribute("","","isCentrallyMaintained","CDATA",(m_Processpara.isCentrallyMaintained()== true ? "true":"false")); - atts.addAttribute("","","isMandatory","CDATA",(m_Processpara.isMandatory()== true ? "true":"false")); - atts.addAttribute("","","isRange","CDATA",(m_Processpara.isRange()== true ? "true":"false")); - return atts; - } - - public static AttributesImpl createmessageBinding( AttributesImpl atts, X_AD_Message m_Message) - { - atts.clear(); - //FIXME: may not need this I guess - //atts.addAttribute("","","AccessLevel","CDATA",(m_Message.getAccessLevel () != null ? m_Message.getAccessLevel ():"")); - atts.addAttribute("","","MsgText","CDATA",(m_Message.getMsgText() != null ? m_Message.getMsgText():"")); - atts.addAttribute("","","MsgType","CDATA",(m_Message.getMsgType() != null ? m_Message.getMsgType ():"")); - atts.addAttribute("","","MsgTip","CDATA",(m_Message.getMsgTip() != null ? m_Message.getMsgTip ():"")); - atts.addAttribute("","","Value","CDATA",(m_Message.getValue() != null ? m_Message.getValue ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Message.getEntityType () != null ? m_Message.getEntityType ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Message.isActive()== true ? "true":"false")); - return atts; - } - - public static AttributesImpl createdynamicvalidationruleBinding( AttributesImpl atts, X_AD_Val_Rule m_ValRule) - { - atts.clear(); - atts.addAttribute("","","Name","CDATA",(m_ValRule.getName () != null ? m_ValRule.getName ():"")); - //FIXME: may not need this I guess - //atts.addAttribute("","","AccessLevel","CDATA",(m_ValRule.getAccessLevel () != null ? m_ValRule.getAccessLevel ():"")); - atts.addAttribute("","","Code","CDATA",(m_ValRule.getCode() != null ? m_ValRule.getCode ():"")); - atts.addAttribute("","","Description","CDATA",(m_ValRule.getDescription () != null ? m_ValRule.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_ValRule.getEntityType () != null ? m_ValRule.getEntityType ():"")); - atts.addAttribute("","","Type","CDATA",(m_ValRule.getType () != null ? m_ValRule.getType ():"")); - atts.addAttribute("","","isActive","CDATA",(m_ValRule.isActive()== true ? "true":"false")); - return atts; - } - - public static AttributesImpl createworkflowBinding( AttributesImpl atts, X_AD_Workflow m_Workflow) - { - String sql = null; - String name = null; - atts.clear(); - atts.addAttribute("","","Name","CDATA",(m_Workflow.getName () != null ? m_Workflow.getName ():"")); - if (m_Workflow.getAD_Table_ID()> 0 ){ - sql = "SELECT Name FROM AD_Table WHERE AD_Table_ID=?"; - name = DB.getSQLValueString(null,sql,m_Workflow.getAD_Table_ID()); - atts.addAttribute("","","ADTableNameID","CDATA",name); - } - else - atts.addAttribute("","","ADTableNameID","CDATA",""); - - if (m_Workflow.getAD_WF_Node_ID()> 0 ){ - sql = "SELECT Name FROM AD_WF_Node WHERE AD_WF_Node_ID=?"; - name = DB.getSQLValueString(null,sql,m_Workflow.getAD_WF_Node_ID()); - atts.addAttribute("","","ADWorkflowNodeNameID","CDATA",name); - } - else - atts.addAttribute("","","ADWorkflowNodeNameID","CDATA",""); - if (m_Workflow.getAD_WF_Responsible_ID()> 0 ){ - sql = "SELECT Name FROM AD_WF_Responsible WHERE AD_WF_Responsible_ID=?"; - name = DB.getSQLValueString(null,sql,m_Workflow.getAD_WF_Responsible_ID()); - atts.addAttribute("","","ADWorkflowResponsibleNameID","CDATA",name); - } - else - atts.addAttribute("","","ADWorkflowResponsibleNameID","CDATA",""); - if (m_Workflow.getAD_WorkflowProcessor_ID()> 0 ){ - sql = "SELECT Name FROM AD_WorkflowProcessor_ID WHERE AD_WorkflowProcessor_ID=?"; - name = DB.getSQLValueString(null,sql,m_Workflow.getAD_WorkflowProcessor_ID()); - atts.addAttribute("","","ADWorkflowProcessorNameID","CDATA",name); - } - else - atts.addAttribute("","","ADWorkflowProcessorNameID","CDATA",""); - atts.addAttribute("","","AccessLevel","CDATA",(m_Workflow.getAccessLevel () != null ? m_Workflow.getAccessLevel ():"")); - atts.addAttribute("","","DurationUnit","CDATA",(m_Workflow.getDurationUnit() != null ? m_Workflow.getDurationUnit ():"")); - atts.addAttribute("","","Help","CDATA",(m_Workflow.getHelp() != null ? m_Workflow.getHelp():"")); - atts.addAttribute("","","Description","CDATA",(m_Workflow.getDescription () != null ? m_Workflow.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Workflow.getEntityType () != null ? m_Workflow.getEntityType ():"")); - atts.addAttribute("","","Author","CDATA",(m_Workflow.getAuthor () != null ? m_Workflow.getAuthor ():"")); - atts.addAttribute("","","Version","CDATA",(""+m_Workflow.getVersion() != null ? ""+m_Workflow.getVersion ():"")); - //FIXME: Handle dates - //atts.addAttribute("","","ValidFrom","CDATA",(m_Workflow.getValidFrom ().toGMTString() != null ? m_Workflow.getValidFrom().toGMTString():"")); - //atts.addAttribute("","","ValidTo","CDATA",(m_Workflow.getValidTo ().toGMTString() != null ? m_Workflow.getValidTo().toGMTString():"")); - atts.addAttribute("","","Priority","CDATA",(""+m_Workflow.getPriority ())); - atts.addAttribute("","","Limit","CDATA",(""+m_Workflow.getLimit())); - atts.addAttribute("","","Duration","CDATA",(""+m_Workflow.getDuration())); - atts.addAttribute("","","Cost","CDATA",(""+m_Workflow.getCost () )); - atts.addAttribute("","","WorkingTime","CDATA",(""+m_Workflow.getWorkingTime() )); - atts.addAttribute("","","WaitingTime","CDATA",(""+m_Workflow.getWaitingTime() )); - atts.addAttribute("","","PublishStatus","CDATA",(m_Workflow.getPublishStatus() != null ? m_Workflow.getPublishStatus():"")); - atts.addAttribute("","","WorkflowType","CDATA",(m_Workflow.getWorkflowType () != null ? m_Workflow.getWorkflowType ():"")); - atts.addAttribute("","","DocValueLogic","CDATA",(m_Workflow.getDocValueLogic() != null ? m_Workflow.getDocValueLogic():"")); - atts.addAttribute("","","isValid","CDATA",(m_Workflow.isValid()== true ? "true":"false")); - //Doesn't appear to be necessary - //atts.addAttribute("","","SetupTime","CDATA",(""+m_Workflow.getSetupTime() != null ? ""+m_Workflow.getSetupTime():"")); - return atts; - } - - public static AttributesImpl createtableBinding( AttributesImpl atts, X_AD_Table m_Table) - { - String sql = null; - String name = null; - atts.clear(); - atts.addAttribute("","","Name","CDATA",(m_Table.getName () != null ? m_Table.getName ():"")); - if (m_Table.getAD_Table_ID()> 0 ){ - sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; - name = DB.getSQLValueString(null,sql,m_Table.getAD_Table_ID()); - atts.addAttribute("","","ADTableNameID","CDATA",name); - } - else - atts.addAttribute("","","ADTableNameID","CDATA",""); - if (m_Table.getAD_Window_ID()> 0 ){ - sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; - name = DB.getSQLValueString(null,sql,m_Table.getAD_Window_ID()); - atts.addAttribute("","","ADWindowNameID","CDATA",name); - } - else - atts.addAttribute("","","ADWindowNameID","CDATA",""); - if (m_Table.getPO_Window_ID()> 0 ){ - sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; - name = DB.getSQLValueString(null,sql,m_Table.getPO_Window_ID()); - atts.addAttribute("","","POWindowNameID","CDATA",name); - } - else - atts.addAttribute("","","POWindowNameID","CDATA",""); - if (m_Table.getAD_Val_Rule_ID()> 0 ){ - sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?"; - name = DB.getSQLValueString(null,sql,m_Table.getAD_Val_Rule_ID()); - atts.addAttribute("","","ADValRuleNameID","CDATA",name); - } - else - atts.addAttribute("","","ADValRuleNameID","CDATA",""); - atts.addAttribute("","","AccessLevel","CDATA",(m_Table.getAccessLevel () != null ? m_Table.getAccessLevel ():"")); - atts.addAttribute("","","Description","CDATA",(m_Table.getDescription () != null ? m_Table.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Table.getEntityType () != null ? m_Table.getEntityType ():"")); - atts.addAttribute("","","Help","CDATA",(m_Table.getHelp() != null ? m_Table.getHelp ():"")); - atts.addAttribute("","","ImportTable","CDATA",(m_Table.getImportTable () != null ? m_Table.getImportTable ():"")); - atts.addAttribute("","","isChangeLog","CDATA",(m_Table.isChangeLog()== true ? "true":"false")); - atts.addAttribute("","","isActive","CDATA",(m_Table.isActive()== true ? "true":"false")); - atts.addAttribute("","","isDeleteable","CDATA",(m_Table.isDeleteable()== true ? "true":"false")); - atts.addAttribute("","","isHighVolume","CDATA",(m_Table.isHighVolume()== true ? "true":"false")); - atts.addAttribute("","","isSecurityEnabled","CDATA",(m_Table.isSecurityEnabled()== true ? "true":"false")); - atts.addAttribute("","","isView","CDATA",(m_Table.isView()== true ? "true":"false")); - atts.addAttribute("","","LoadSeq","CDATA",(m_Table.getLoadSeq ()> 0 ? "" + m_Table.getLoadSeq ():"")); - atts.addAttribute("","","ReplicationType","CDATA",(m_Table.getReplicationType () != null ? m_Table.getReplicationType ():"")); - atts.addAttribute("","","TableName","CDATA",(m_Table.getTableName () != null ? m_Table.getTableName ():"")); - return atts; - } - - public static AttributesImpl createwf_nodeBinding( AttributesImpl atts, X_AD_WF_Node m_WF_Node) - { - String sql = null; - String name = null; - atts.clear(); - - atts.addAttribute("","","Name","CDATA",(m_WF_Node.getName () != null ? m_WF_Node.getName():"")); - - if (m_WF_Node.getAD_Workflow_ID()> 0 ){ - sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_Node.getAD_Workflow_ID()); - atts.addAttribute("","","ADWorkflowNameID","CDATA",name); - } - else - atts.addAttribute("","","ADWorkflowNameID","CDATA",""); - - if (m_WF_Node.getAD_Window_ID()> 0 ){ - sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_Node.getAD_Window_ID()); - } - if (name != null ) - atts.addAttribute("","","ADWindowNameID","CDATA",name); - else - atts.addAttribute("","","ADWindowNameID","CDATA",""); - - if (m_WF_Node.getAD_Task_ID()> 0 ){ - sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_Node.getAD_Task_ID()); - } - if (name != null ) - atts.addAttribute("","","ADTaskNameID","CDATA",name); - else - atts.addAttribute("","","ADTaskNameID","CDATA",""); - - if (m_WF_Node.getAD_Process_ID()> 0 ){ - sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_Node.getAD_Process_ID()); - atts.addAttribute("","","ADProcessNameID","CDATA",name); - } - else - atts.addAttribute("","","ADProcessNameID","CDATA",""); - if (m_WF_Node.getAD_Form_ID()> 0 ){ - sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_Node.getAD_Form_ID()); - atts.addAttribute("","","ADFormNameID","CDATA",name); - } - else - atts.addAttribute("","","ADFormNameID","CDATA",""); - if (m_WF_Node.getAD_WF_Block_ID()> 0 ){ - sql = "SELECT Name FROM AD_WF_Block WHERE AD_WF_Block_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_Node.getAD_WF_Block_ID()); - atts.addAttribute("","","ADWorkflowBlockNameID","CDATA",name); - } - else - atts.addAttribute("","","ADWorkflowBlockNameID","CDATA",""); - if (m_WF_Node.getAD_WF_Responsible_ID()> 0 ){ - sql = "SELECT Name FROM AD_WF_Responsible WHERE AD_WF_Responsible_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_Node.getAD_WF_Responsible_ID()); - atts.addAttribute("","","ADWorkflowResponsibleNameID","CDATA",name); - } - else - atts.addAttribute("","","ADWorkflowResponsibleNameID","CDATA",""); - - if (m_WF_Node.getAD_Image_ID()> 0 ){ - sql = "SELECT Name FROM AD_Image WHERE AD_Image_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_Node.getAD_Image_ID()); - } - if (name != null ) - atts.addAttribute("","","ADImageNameID","CDATA",name); - else - atts.addAttribute("","","ADImageNameID","CDATA",""); - if (m_WF_Node.getAD_Column_ID()> 0 ){ - sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_Node.getAD_Column_ID()); - atts.addAttribute("","","ADColumnNameID","CDATA",name); - } - else - atts.addAttribute("","","ADColumnNameID","CDATA",""); - atts.addAttribute("","","isActive","CDATA",(m_WF_Node.isActive()== true ? "true":"false")); - atts.addAttribute("","","Description","CDATA",(m_WF_Node.getDescription () != null ? m_WF_Node.getDescription ():"")); - atts.addAttribute("","","Help","CDATA",(m_WF_Node.getHelp () != null ? m_WF_Node.getHelp ():"")); - atts.addAttribute("","","isCentrallyMaintained","CDATA",(m_WF_Node.isCentrallyMaintained ()== true ? "true":"false")); - - atts.addAttribute("","","Action","CDATA",(m_WF_Node.getAction () != null ? m_WF_Node.getAction ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_WF_Node.getEntityType () != null ? m_WF_Node.getEntityType ():"")); - atts.addAttribute("","","XPosition","CDATA",(""+m_WF_Node.getXPosition ())); - atts.addAttribute("","","YPosition","CDATA",(""+m_WF_Node.getYPosition ())); - atts.addAttribute("","","SubflowExecution","CDATA",(m_WF_Node.getSubflowExecution () != null ? m_WF_Node.getSubflowExecution ():"")); - atts.addAttribute("","","StartMode","CDATA",(m_WF_Node.getStartMode () != null ? m_WF_Node.getStartMode ():"")); - atts.addAttribute("","","Priority","CDATA",(""+m_WF_Node.getPriority ())); - atts.addAttribute("","","Duration","CDATA",(""+m_WF_Node.getDuration () )); - atts.addAttribute("","","Cost","CDATA",(""+m_WF_Node.getCost () )); - atts.addAttribute("","","WorkingTime","CDATA",(""+m_WF_Node.getWorkingTime() )); - atts.addAttribute("","","WaitingTime","CDATA",(""+m_WF_Node.getWaitingTime() )); - atts.addAttribute("","","JoinElement","CDATA",(m_WF_Node.getJoinElement() != null ? m_WF_Node.getJoinElement():"")); - atts.addAttribute("","","SplitElement","CDATA",(m_WF_Node.getSplitElement() != null ? m_WF_Node.getSplitElement():"")); - atts.addAttribute("","","WaitTime","CDATA",(""+m_WF_Node.getWaitTime() )); - atts.addAttribute("","","AttributeName","CDATA",(m_WF_Node.getAttributeName() != null ? m_WF_Node.getAttributeName():"")); - atts.addAttribute("","","AttributeValue","CDATA",(m_WF_Node.getAttributeValue() != null ? m_WF_Node.getAttributeValue():"")); - atts.addAttribute("","","DocAction","CDATA",(m_WF_Node.getDocAction() != null ? m_WF_Node.getDocAction():"")); - atts.addAttribute("","","DynPriorityUnit","CDATA",(m_WF_Node.getDynPriorityUnit() != null ? m_WF_Node.getDynPriorityUnit():"")); - atts.addAttribute("","","DynPriorityChange","CDATA",(""+m_WF_Node.getDynPriorityChange() )); - - return atts; - } - - public static AttributesImpl createwf_nodenextBinding( AttributesImpl atts, X_AD_WF_NodeNext m_WF_NodeNext) - //public AttributesImpl createwf_nodenextBinding( AttributesImpl atts, X_AD_WF_NodeNext m_WF_NodeNext, X_AD_WF_Node m_WF_Node) - { - String sql = null; - String name = null; - atts.clear(); - //log.log(Level.INFO,"m_WF_NodeNext.getAD_WF_Node_ID: ", m_WF_NodeNext.getAD_WF_Node_ID()); - //log.log(Level.INFO,"m_WF_NodeNext.getAD_WF_Next_ID: ", m_WF_NodeNext.getAD_WF_Next_ID()); - - if (m_WF_NodeNext.getAD_WF_Node_ID() > 0 ){ - sql = "SELECT AD_Workflow.Name FROM AD_Workflow, AD_WF_Node WHERE AD_Workflow.AD_Workflow_ID = AD_WF_Node.AD_Workflow_ID and AD_WF_Node.AD_WF_Node_ID =?"; - name = DB.getSQLValueString(null,sql,m_WF_NodeNext.getAD_WF_Node_ID()); - atts.addAttribute("","","ADWorkflowNameID","CDATA",name); - sql = "SELECT Name FROM AD_WF_Node WHERE AD_WF_Node_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_NodeNext.getAD_WF_Node_ID()); - atts.addAttribute("","","ADWorkflowNodeNameID","CDATA",name); - } - - if (m_WF_NodeNext.getAD_WF_Next_ID() > 0 ){ - sql = "SELECT Name FROM AD_WF_Node WHERE AD_WF_Node_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_NodeNext.getAD_WF_Next_ID()); - //log.log(Level.INFO,"node next name: ", name); - atts.addAttribute("","","ADWorkflowNodeNextNameID","CDATA",name); - } - - // FIXME: don't know if I need org_id or not - //sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?"; - //name = DB.getSQLValueString(null,sql,org_id); - //atts.addAttribute("","","orgname","CDATA",name); - - atts.addAttribute("","","isActive","CDATA",(m_WF_NodeNext.isActive()== true ? "true":"false")); - atts.addAttribute("","","EntityType","CDATA",(m_WF_NodeNext.getEntityType () != null ? m_WF_NodeNext.getEntityType ():"")); - atts.addAttribute("","","Description","CDATA",(m_WF_NodeNext.getDescription () != null ? m_WF_NodeNext.getDescription ():"")); - atts.addAttribute("","","SeqNo","CDATA",(String.valueOf(m_WF_NodeNext.getSeqNo ()) != null ? String.valueOf(m_WF_NodeNext.getSeqNo ()):"")); - atts.addAttribute("","","IsStdUserWorkflow","CDATA",(String.valueOf(m_WF_NodeNext.isStdUserWorkflow ()) != null ? String.valueOf(m_WF_NodeNext.isStdUserWorkflow ()):"")); - - return atts; - } - - public static AttributesImpl createwf_nodenextconditionBinding( AttributesImpl atts, X_AD_WF_NextCondition m_WF_NodeNextCondition) - { - String sql = null; - String name = null; - atts.clear(); - - if (m_WF_NodeNextCondition.getAD_WF_NodeNext_ID() > 0 ){ - //FIXME: it appears nodes point back to themselves - // so a group by is necessary - sql = "SELECT AD_Workflow.Name FROM AD_Workflow, AD_WF_Node, AD_WF_NodeNext WHERE AD_Workflow.AD_Workflow_ID = AD_WF_Node.AD_Workflow_ID and AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_Workflow.Name"; - name = DB.getSQLValueString(null,sql,m_WF_NodeNextCondition.getAD_WF_NodeNext_ID()); - atts.addAttribute("","","ADWorkflowNameID","CDATA",name); - //FIXME: it appears nodes point back to themselves - // so a group by is necessary - sql = "SELECT AD_WF_Node.Name FROM AD_WF_Node, AD_WF_NodeNext WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_WF_Node.Name"; - name = DB.getSQLValueString(null,sql,m_WF_NodeNextCondition.getAD_WF_NodeNext_ID()); - atts.addAttribute("","","ADWorkflowNodeNameID","CDATA",name); - //FIXME: it appears nodes point back to themselves - // so a group by is necessary - sql = "SELECT AD_WF_Node.Name FROM AD_WF_Node, AD_WF_NodeNext, AD_WF_NextCondition WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Next_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_WF_Node.Name"; - name = DB.getSQLValueString(null,sql,m_WF_NodeNextCondition.getAD_WF_NodeNext_ID()); - //log.log(Level.INFO,"node next name: ", name); - atts.addAttribute("","","ADWorkflowNodeNextNameID","CDATA",name); - } - - if (m_WF_NodeNextCondition.getAD_Column_ID()> 0 ){ - - sql = "SELECT AD_Table.TableName FROM AD_Table, AD_Column, AD_WF_NextCondition WHERE AD_Column.AD_Table_ID=AD_Table.AD_Table_ID and AD_Column.AD_Column_ID = ?"; - name = DB.getSQLValueString(null,sql,m_WF_NodeNextCondition.getAD_Column_ID()); - atts.addAttribute("","","ADTableNameID","CDATA",name); - - sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,m_WF_NodeNextCondition.getAD_Column_ID()); - atts.addAttribute("","","ADColumnNameID","CDATA",name); - } -else { - atts.addAttribute("","","ADTableNameID","CDATA",name); - atts.addAttribute("","","ADColumnNameID","CDATA",""); - } - - // FIXME: don't know if I need org_id or not - //sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?"; - //name = DB.getSQLValueString(null,sql,org_id); - //atts.addAttribute("","","orgname","CDATA",name); - - atts.addAttribute("","","isActive","CDATA",(m_WF_NodeNextCondition.isActive()== true ? "true":"false")); - atts.addAttribute("","","EntityType","CDATA",(m_WF_NodeNextCondition.getEntityType () != null ? m_WF_NodeNextCondition.getEntityType ():"")); - atts.addAttribute("","","AndOr","CDATA",(m_WF_NodeNextCondition.getAndOr () != null ? m_WF_NodeNextCondition.getAndOr ():"")); - atts.addAttribute("","","Operation","CDATA",(m_WF_NodeNextCondition.getOperation () != null ? m_WF_NodeNextCondition.getOperation ():"")); - atts.addAttribute("","","Value","CDATA",(m_WF_NodeNextCondition.getValue () != null ? m_WF_NodeNextCondition.getValue ():"")); - atts.addAttribute("","","Value2","CDATA",(m_WF_NodeNextCondition.getValue2 () != null ? m_WF_NodeNextCondition.getValue2 ():"")); - atts.addAttribute("","","SeqNo","CDATA",(String.valueOf(m_WF_NodeNextCondition.getSeqNo ()) != null ? String.valueOf(m_WF_NodeNextCondition.getSeqNo ()):"")); - - return atts; - } - - public static AttributesImpl createcolumnBinding( AttributesImpl atts, X_AD_Column m_Column) - { - String sql = null; - String name = null; - atts.clear(); - if (m_Column.getAD_Column_ID()> 0 ){ - sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,m_Column.getAD_Column_ID()); - atts.addAttribute("","","ADColumnNameID","CDATA",name); - } - else - atts.addAttribute("","","ADColumnNameID","CDATA",""); - if (m_Column.getAD_Process_ID()> 0 ){ - sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; - name = DB.getSQLValueString(null,sql,m_Column.getAD_Process_ID()); - atts.addAttribute("","","ADProcessNameID","CDATA",name); - } - else - atts.addAttribute("","","ADProcessNameID","CDATA",""); - if (m_Column.getAD_Element_ID()> 0 ){ - sql = "SELECT Name FROM AD_Element WHERE AD_Element_ID=?"; - name = DB.getSQLValueString(null,sql,m_Column.getAD_Element_ID()); - atts.addAttribute("","","ADElementNameID","CDATA",name); - } - else - atts.addAttribute("","","ADElementNameID","CDATA",""); - if (m_Column.getAD_Reference_ID()> 0 ){ - sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; - name = DB.getSQLValueString(null,sql,m_Column.getAD_Reference_ID()); - atts.addAttribute("","","ADReferenceNameID","CDATA",name); - } - else - atts.addAttribute("","","ADReferenceNameID","CDATA",""); - if (m_Column.getAD_Reference_Value_ID()> 0 ){ - sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; - name = DB.getSQLValueString(null,sql,m_Column.getAD_Reference_Value_ID()); - atts.addAttribute("","","ADReferenceNameValueID","CDATA",name); - } - else - atts.addAttribute("","","ADReferenceNameValueID","CDATA",""); - if (m_Column.getAD_Table_ID()> 0 ){ - sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; - name = DB.getSQLValueString(null,sql,m_Column.getAD_Table_ID()); - atts.addAttribute("","","ADTableNameID","CDATA",name); - } - else - atts.addAttribute("","","ADTableNameID","CDATA",""); - if (m_Column.getAD_Val_Rule_ID()> 0 ){ - sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?"; - name = DB.getSQLValueString(null,sql,m_Column.getAD_Val_Rule_ID()); - atts.addAttribute("","","ADValRuleNameID","CDATA",name); - } - else - atts.addAttribute("","","ADValRuleNameID","CDATA",""); - atts.addAttribute("","","Callout","CDATA",(m_Column.getCallout () != null ? m_Column.getCallout ():"")); - atts.addAttribute("","","ColumnSQL","CDATA",(m_Column.getColumnSQL () != null ? m_Column.getColumnSQL ():"")); - atts.addAttribute("","","ColumnName","CDATA",(m_Column.getColumnName () != null ? m_Column.getColumnName ():"")); - atts.addAttribute("","","DefaultValue","CDATA",(m_Column.getDefaultValue () != null ? m_Column.getDefaultValue ():"")); - atts.addAttribute("","","Description","CDATA",(m_Column.getDescription () != null ? m_Column.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Column.getEntityType () != null ? m_Column.getEntityType ():"")); - atts.addAttribute("","","FieldLength","CDATA",(m_Column.getFieldLength () > 0 ? "" + m_Column.getFieldLength ():"0")); - atts.addAttribute("","","Help","CDATA",(m_Column.getHelp () != null ? m_Column.getHelp ():"")); - atts.addAttribute("","","isAlwaysUpdateable","CDATA",(m_Column.isAlwaysUpdateable()== true ? "true":"false")); - //atts.addAttribute("","","isEncrypted","CDATA",(m_Column.getIsEncrypted()== true ? "true":"false")); - atts.addAttribute("","","isIdentifier","CDATA",(m_Column.isIdentifier()== true ? "true":"false")); - atts.addAttribute("","","isKey","CDATA",(m_Column.isKey()== true ? "true":"false")); - atts.addAttribute("","","isMandatory","CDATA",(m_Column.isMandatory()== true ? "true":"false")); - atts.addAttribute("","","isParent","CDATA",(m_Column.isParent()== true ? "true":"false")); - atts.addAttribute("","","isSelectionColumn","CDATA",(m_Column.isSelectionColumn()== true ? "true":"false")); - atts.addAttribute("","","isActive","CDATA",(m_Column.isActive()== true ? "true":"false")); - atts.addAttribute("","","isTranslated","CDATA",(m_Column.isTranslated()== true ? "true":"false")); - atts.addAttribute("","","isUpdateable","CDATA",(m_Column.isUpdateable()== true ? "true":"false")); - atts.addAttribute("","","Name","CDATA",(m_Column.getName () != null ? m_Column.getName ():"")); - atts.addAttribute("","","getIsSyncDatabase","CDATA",(m_Column.getIsSyncDatabase () != null ? m_Column.getIsSyncDatabase ():"")); - atts.addAttribute("","","ReadOnlyLogic","CDATA",(m_Column.getReadOnlyLogic () != null ? m_Column.getReadOnlyLogic ():"")); - atts.addAttribute("","","SeqNo","CDATA",(m_Column.getSeqNo ()> 0 ? "" + m_Column.getSeqNo ():"0")); - atts.addAttribute("","","VFormat","CDATA",(m_Column.getVFormat () != null ? m_Column.getVFormat ():"")); - atts.addAttribute("","","ValueMax","CDATA",(m_Column.getValueMax () != null ? m_Column.getValueMax ():"")); - atts.addAttribute("","","ValueMin","CDATA",(m_Column.getValueMin () != null ? m_Column.getValueMin ():"")); - atts.addAttribute("","","Version","CDATA",(m_Column.getVersion()!= null ? "" + m_Column.getVersion ():"0.0")); - return atts; - } - - public static AttributesImpl createtaskBinding( AttributesImpl atts, X_AD_Task m_Task) - { - String sql = null; - String name = null; - atts.clear(); - if (m_Task.getAD_Task_ID()> 0 ){ - sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?"; - name = DB.getSQLValueString(null,sql,m_Task.getAD_Task_ID()); - } - if (name != null ) - atts.addAttribute("","","ADTaskNameID","CDATA",name); - else - atts.addAttribute("","","ADTaskNameID","CDATA",""); - atts.addAttribute("","","AccessLevel","CDATA",(m_Task.getAccessLevel () != null ? m_Task.getAccessLevel ():"")); - atts.addAttribute("","","Description","CDATA",(m_Task.getDescription () != null ? m_Task.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Task.getEntityType () != null ? m_Task.getEntityType ():"")); - atts.addAttribute("","","Help","CDATA",(m_Task.getHelp () != null ? m_Task.getHelp ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Task.isActive()== true ? "true":"false")); - atts.addAttribute("","","Name","CDATA",(m_Task.getName () != null ? m_Task.getName ():"")); - atts.addAttribute("","","OS_Command","CDATA",(m_Task.getOS_Command () != null ? m_Task.getOS_Command ():"")); - return atts; - } - - public static AttributesImpl createformBinding( AttributesImpl atts, X_AD_Form m_Form) - { - String sql = null; - String name = null; - atts.clear(); - if (m_Form.getAD_Form_ID()> 0 ){ - sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?"; - name = DB.getSQLValueString(null,sql,m_Form.getAD_Form_ID()); - } - if (name != null ) - atts.addAttribute("","","ADFormNameID","CDATA",name); - else - atts.addAttribute("","","ADFormNameID","CDATA",""); - atts.addAttribute("","","Classname","CDATA",(m_Form.getClassname () != null ? m_Form.getClassname ():"")); - atts.addAttribute("","","isBetaFunctionality","CDATA",(m_Form.isBetaFunctionality()== true ? "true":"false")); - atts.addAttribute("","","AccessLevel","CDATA",(m_Form.getAccessLevel () != null ? m_Form.getAccessLevel ():"")); - atts.addAttribute("","","Description","CDATA",(m_Form.getDescription () != null ? m_Form.getDescription ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Form.isActive()== true ? "true":"false")); - atts.addAttribute("","","EntityType","CDATA",(m_Form.getEntityType () != null ? m_Form.getEntityType ():"")); - atts.addAttribute("","","Help","CDATA",(m_Form.getHelp() != null ? m_Form.getHelp():"")); - atts.addAttribute("","","Name","CDATA",(m_Form.getName() != null ? m_Form.getName():"")); - return atts; - } - - public static AttributesImpl createworkbenchBinding( AttributesImpl atts, X_AD_Workbench m_Workbench) - { - String sql = null; - String name = null; - atts.clear(); - if (m_Workbench.getAD_Workbench_ID()> 0 ){ - sql = "SELECT Name FROM AD_Workbench WHERE AD_Workbench_ID=?"; - name = DB.getSQLValueString(null,sql,m_Workbench.getAD_Workbench_ID()); - } - if (name != null ) - atts.addAttribute("","","ADWorkbenchNameID","CDATA",name); - else - atts.addAttribute("","","ADWorkbenchNameID","CDATA",""); - if (m_Workbench.getAD_Column_ID()> 0 ){ - sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,m_Workbench.getAD_Column_ID()); - } - if (name != null ) - atts.addAttribute("","","ADColumnNameID","CDATA",name); - else - atts.addAttribute("","","ADColumnNameID","CDATA",""); - atts.addAttribute("","","Description","CDATA",(m_Workbench.getDescription () != null ? m_Workbench.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Workbench.getEntityType () != null ? m_Workbench.getEntityType ():"")); - atts.addAttribute("","","Help","CDATA",(m_Workbench.getHelp () != null ? m_Workbench.getHelp ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Workbench.isActive()== true ? "true":"false")); - atts.addAttribute("","","Name","CDATA",(m_Workbench.getName () != null ? m_Workbench.getName ():"")); - //atts.addAttribute("","","PA_Goal_ID","CDATA",(m_Workbench.getPA_Goal_ID() > 0 ? "" + m_Workbench.getPA_Goal_ID ():"")); - return atts; - } - - public static AttributesImpl createworkbenchwindowBinding( AttributesImpl atts, X_AD_WorkbenchWindow m_Workbenchwindow) - { - String sql = null; - String name = null; - atts.clear(); - if (m_Workbenchwindow.getAD_Process_ID()> 0 ){ - sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; - name = DB.getSQLValueString(null,sql,m_Workbenchwindow.getAD_Process_ID()); - atts.addAttribute("","","name","CDATA",name); - } - else - atts.addAttribute("","","name","CDATA",""); - if (m_Workbenchwindow.getAD_Workbench_ID()> 0 ){ - sql = "SELECT Name FROM AD_Workbench WHERE AD_Workbench_ID=?"; - name = DB.getSQLValueString(null,sql,m_Workbenchwindow.getAD_Workbench_ID()); - } - if (name != null ) - atts.addAttribute("","","ADWorkbenchNameID","CDATA",name); - else - atts.addAttribute("","","ADWorkbenchNameID","CDATA",""); - if (m_Workbenchwindow.getAD_Form_ID()> 0 ){ - sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?"; - name = DB.getSQLValueString(null,sql,m_Workbenchwindow.getAD_Form_ID()); - } - if (name != null ) - atts.addAttribute("","","ADFormNameID","CDATA",name); - else - atts.addAttribute("","","ADFormNameID","CDATA",""); - if (m_Workbenchwindow.getAD_Window_ID()> 0 ){ - sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; - name = DB.getSQLValueString(null,sql,m_Workbenchwindow.getAD_Window_ID()); - } - if (name != null ) - atts.addAttribute("","","ADWindowNameID","CDATA",name); - else - atts.addAttribute("","","ADWindowNameID","CDATA",""); - if (m_Workbenchwindow.getAD_Task_ID()> 0 ){ - sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?"; - name = DB.getSQLValueString(null,sql,m_Workbenchwindow.getAD_Task_ID()); - } - if (name != null ) - atts.addAttribute("","","ADTaskNameID","CDATA",name); - else - atts.addAttribute("","","ADTaskNameID","CDATA",""); - atts.addAttribute("","","EntityType","CDATA",(m_Workbenchwindow.getEntityType () != null ? m_Workbenchwindow.getEntityType ():"")); - atts.addAttribute("","","SeqNo","CDATA",(m_Workbenchwindow.getSeqNo () > 0 ? "" + m_Workbenchwindow.getSeqNo ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Workbenchwindow.isActive()== true ? "true":"false")); - atts.addAttribute("","","isPrimary","CDATA",(m_Workbenchwindow.isPrimary()== true ? "true":"false")); - return atts; - } - - public static AttributesImpl createreferenceBinding( AttributesImpl atts, X_AD_Reference m_Reference) - { - String sql = null; - String name = null; - atts.clear(); - if (m_Reference.getAD_Reference_ID()> 0 ){ - sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; - name = DB.getSQLValueString(null,sql,m_Reference.getAD_Reference_ID()); - atts.addAttribute("","","name","CDATA",name); - } - else - atts.addAttribute("","","name","CDATA",""); - atts.addAttribute("","","Description","CDATA",(m_Reference.getDescription () != null ? m_Reference.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Reference.getEntityType () != null ? m_Reference.getEntityType ():"")); - atts.addAttribute("","","Help","CDATA",(m_Reference.getHelp () != null ? m_Reference.getHelp ():"")); - atts.addAttribute("","","Name","CDATA",(m_Reference.getName () != null ? m_Reference.getName ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Reference.isActive()== true ? "true":"false")); - atts.addAttribute("","","VFormat","CDATA",(m_Reference.getVFormat () != null ? m_Reference.getVFormat ():"")); - atts.addAttribute("","","ValidationType","CDATA",(m_Reference.getValidationType () != null ? m_Reference.getValidationType ():"")); - return atts; - } - - public static AttributesImpl createimpBinding( AttributesImpl atts, X_AD_ImpFormat m_ImpFormat) - { - atts.clear(); - if (m_ImpFormat.getAD_Table_ID()> 0 ){ - String sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; - String name = DB.getSQLValueString(null,sql,m_ImpFormat.getAD_Table_ID()); - atts.addAttribute("","","ADTableNameID","CDATA",name); - } - else - atts.addAttribute("","","ADTableNameID","CDATA",""); - - atts.addAttribute("","","Name","CDATA",(m_ImpFormat.getName () != null ? m_ImpFormat.getName ():"")); - atts.addAttribute("","","isActive","CDATA",(m_ImpFormat.isActive()== true ? "true":"false")); - atts.addAttribute("","","isProcessing","CDATA",(m_ImpFormat.isProcessing()== true ? "true":"false")); - atts.addAttribute("","","Description","CDATA",(m_ImpFormat.getDescription () != null ? m_ImpFormat.getDescription():"")); - atts.addAttribute("","","FormatType","CDATA",(m_ImpFormat.getFormatType () != null ? m_ImpFormat.getFormatType():"")); - return atts; - } - - public static AttributesImpl createimprowBinding( AttributesImpl atts, X_AD_ImpFormat_Row m_ImpFormat_Row) - { - String sql = null; - String name = null; - atts.clear(); - if (m_ImpFormat_Row.getAD_ImpFormat_ID()> 0 ){ - sql = "SELECT Name FROM AD_ImpFormat WHERE AD_ImpFormat_ID=?"; - name = DB.getSQLValueString(null,sql,m_ImpFormat_Row.getAD_ImpFormat_ID()); - atts.addAttribute("","","ADImpFormatNameID","CDATA",name); - } - else - atts.addAttribute("","","ADImpFormatNameID","CDATA",""); - - if (m_ImpFormat_Row.getAD_Column_ID()> 0 ){ - sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,m_ImpFormat_Row.getAD_Column_ID()); - atts.addAttribute("","","ADColumnNameID","CDATA",name); - } - else - atts.addAttribute("","","ADColumnNameID","CDATA",""); - - if (m_ImpFormat_Row.getAD_Column_ID()> 0 ){ - sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?"; - int idTable = DB.getSQLValue(null, sql,m_ImpFormat_Row.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",""); - - atts.addAttribute("","","Name","CDATA",(m_ImpFormat_Row.getName () != null ? m_ImpFormat_Row.getName ():"")); - atts.addAttribute("","","SeqNo","CDATA",""+m_ImpFormat_Row.getSeqNo()); - atts.addAttribute("","","StartNo","CDATA",""+m_ImpFormat_Row.getStartNo()); - atts.addAttribute("","","EndNo","CDATA",""+m_ImpFormat_Row.getEndNo()); - atts.addAttribute("","","DataType","CDATA",(m_ImpFormat_Row.getDataType () != null ? m_ImpFormat_Row.getDataType():"")); - atts.addAttribute("","","DataFormat","CDATA",(m_ImpFormat_Row.getDataFormat () != null ? m_ImpFormat_Row.getDataFormat():"")); - atts.addAttribute("","","DecimalPoint","CDATA",(m_ImpFormat_Row.getDecimalPoint () != null ? m_ImpFormat_Row.getDecimalPoint():"")); - atts.addAttribute("","","isDivideBy100","CDATA",(m_ImpFormat_Row.isDivideBy100 ()== true ? "true":"false")); - atts.addAttribute("","","ConstantValue","CDATA",(m_ImpFormat_Row.getConstantValue() != null ? m_ImpFormat_Row.getConstantValue():"")); - atts.addAttribute("","","Callout","CDATA",(m_ImpFormat_Row.getCallout() != null ? m_ImpFormat_Row.getCallout():"")); - atts.addAttribute("","","Script","CDATA",(m_ImpFormat_Row.getScript() != null ? m_ImpFormat_Row.getScript():"")); - atts.addAttribute("","","isActive","CDATA",(m_ImpFormat_Row.isActive()== true ? "true":"false")); - - return atts; - } - - public static AttributesImpl createroleBinding( AttributesImpl atts, X_AD_Role m_Role) - { - String sql = null; - String name = null; - atts.clear(); - - if (m_Role.getAD_Tree_Menu_ID()> 0 ){ - sql = "SELECT Name FROM AD_Tree WHERE AD_Tree_ID=? AND AD_Tree.TreeType='MM'"; - name = DB.getSQLValueString(null,sql,m_Role.getAD_Tree_Menu_ID()); - atts.addAttribute("","","treemenuname","CDATA",name); - } - else - atts.addAttribute("","","treemenuname","CDATA",""); - - if (m_Role.getAD_Tree_Org_ID()> 0 ){ - sql = "SELECT Name FROM AD_Tree WHERE AD_Tree_ID=? AND AD_Tree.TreeType='OO'"; - name = DB.getSQLValueString(null,sql,m_Role.getAD_Tree_Org_ID()); - atts.addAttribute("","","treeorgname","CDATA",name); - } - else - atts.addAttribute("","","treeorgname","CDATA",""); - - if (m_Role.getC_Currency_ID()> 0 ){ - sql = "SELECT ISO_Code FROM C_Currency WHERE C_Currency_ID=?"; - name = DB.getSQLValueString(null,sql,m_Role.getC_Currency_ID()); - atts.addAttribute("","","currencycode","CDATA",name); - } - else - atts.addAttribute("","","currencycode","CDATA",""); - - if (m_Role.getSupervisor_ID()> 0 ){ - sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?"; - name = DB.getSQLValueString(null,sql,m_Role.getC_Currency_ID()); - atts.addAttribute("","","supervisorid","CDATA",name); - } - else - atts.addAttribute("","","supervisorid","CDATA",""); - - atts.addAttribute("","","Description","CDATA",(m_Role.getDescription () != null ? m_Role.getDescription ():"")); - atts.addAttribute("","","Name","CDATA",(m_Role.getName () != null ? m_Role.getName ():"")); - atts.addAttribute("","","AmtApproval","CDATA",(""+m_Role.getAmtApproval())); - atts.addAttribute("","","isAccessAllOrgs","CDATA",(m_Role.isAccessAllOrgs()== true ? "true":"false")); - atts.addAttribute("","","isActive","CDATA",(m_Role.isActive()== true ? "true":"false")); - atts.addAttribute("","","isCanApproveOwnDoc","CDATA",(m_Role.isCanApproveOwnDoc()== true ? "true":"false")); - atts.addAttribute("","","isCanExport","CDATA",(m_Role.isCanExport()== true ? "true":"false")); - atts.addAttribute("","","isCanReport","CDATA",(m_Role.isCanReport()== true ? "true":"false")); - atts.addAttribute("","","isChangeLog","CDATA",(m_Role.isChangeLog()== true ? "true":"false")); - atts.addAttribute("","","isManual","CDATA",(m_Role.isManual()== true ? "true":"false")); - atts.addAttribute("","","isPersonalAccess","CDATA",(m_Role.isPersonalAccess()== true ? "true":"false")); - atts.addAttribute("","","isPersonalLock","CDATA",(m_Role.isPersonalLock()== true ? "true":"false")); - atts.addAttribute("","","isShowAcct","CDATA",(m_Role.isShowAcct()== true ? "true":"false")); - atts.addAttribute("","","isUseUserOrgAccess","CDATA",(m_Role.isUseUserOrgAccess()== true ? "true":"false")); - atts.addAttribute("","","isOverwritePriceLimit","CDATA",(m_Role.isOverwritePriceLimit()== true ? "true":"false")); - atts.addAttribute("","","PreferenceType","CDATA",(m_Role.getPreferenceType() != null ? m_Role.getPreferenceType ():"")); - atts.addAttribute("","","UserLevel","CDATA",(m_Role.getUserLevel() != null ? m_Role.getUserLevel ():"")); - - return atts; - } - public static AttributesImpl createSQLStatmentBinding( AttributesImpl atts, String SqlStatement, String DBType) - { - atts.clear(); - atts.addAttribute("","","DBType","CDATA",DBType); - atts.addAttribute("","","statement","CDATA",SqlStatement); - return atts; - - } - - public static AttributesImpl createSnipitBinding( AttributesImpl atts, String FileDir, String FileName, String OldCode, String NewCode, String ReleaseNo) - { - atts.clear(); - atts.addAttribute("","","filedir","CDATA",FileDir); - atts.addAttribute("","","filename","CDATA",FileName); - String preOldCode = OldCode.toString(); - String preNewCode = NewCode.toString(); - String modOldCode = preOldCode.replaceAll("\\$","\\\\\\$").replaceAll("\\.","\\\\.") - .replaceAll("\\^","\\\\^").replaceAll("\\(","\\\\(").replaceAll("\\)","\\\\)") - .replaceAll("\\[","\\\\[").replaceAll("\\/","\\\\/").replaceAll("\\+","\\\\+") - .replaceAll("\\*","\\\\*").replaceAll("\\|","\\\\|"); - String modNewCode = preNewCode.replaceAll("\\$","\\\\\\$").replaceAll("\\.","\\\\.") - .replaceAll("\\^","\\\\^").replaceAll("\\(","\\\\(").replaceAll("\\)","\\\\)") - .replaceAll("\\[","\\\\[").replaceAll("\\/","\\\\/").replaceAll("\\+","\\\\+") - .replaceAll("\\*","\\\\*").replaceAll("\\|","\\\\|"); - atts.addAttribute("","","oldcode","CDATA",modOldCode); - atts.addAttribute("","","newcode","CDATA",modNewCode); - atts.addAttribute("","","ReleaseNo","CDATA",ReleaseNo); - return atts; - - } - - public static AttributesImpl createorgaccessBinding( AttributesImpl atts, int org_id, int role_id) - { - String sql = null; - String name = null; - atts.clear(); - - sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?"; - name = DB.getSQLValueString(null,sql,org_id); - atts.addAttribute("","","orgname","CDATA",name); - - sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; - name = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","rolename","CDATA",name); - - sql = "SELECT isActive FROM AD_Role_OrgAccess WHERE AD_Org_ID="+ org_id +" and AD_Role_ID=?"; - String TrueFalse = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isActive","CDATA",TrueFalse); - - sql = "SELECT isReadOnly FROM AD_Role_OrgAccess WHERE AD_Org_ID="+ org_id +" and AD_Role_ID=?"; - String isReadOnly = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isReadOnly","CDATA",isReadOnly); - - return atts; - } - - //TODO - public static AttributesImpl createusrassignBinding( AttributesImpl atts, int user_id, int role_id, int org_id) - { - String sql = null; - String name = null; - atts.clear(); - - sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?"; - name = DB.getSQLValueString(null,sql,user_id); - atts.addAttribute("","","username","CDATA",name); - - sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; - name = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","rolename","CDATA",name); - - sql = "SELECT isActive FROM AD_User_Roles WHERE AD_User_ID="+ user_id +" and AD_Role_ID=?"; - String TrueFalse = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isActive","CDATA",TrueFalse); - - sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?"; - name = DB.getSQLValueString(null,sql,org_id); - atts.addAttribute("","","orgname","CDATA",name); - - return atts; - } - - public static AttributesImpl createwindowaccessBinding( AttributesImpl atts, int window_id, int role_id) - { - String sql = null; - String name = null; - atts.clear(); - - - sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; - name = DB.getSQLValueString(null,sql,window_id); - atts.addAttribute("","","windowname","CDATA",name); - - sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; - name = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","rolename","CDATA",name); - - sql = "SELECT isActive FROM AD_Window_Access WHERE AD_Window_ID="+ window_id +" and AD_Role_ID=?"; - String TrueFalse = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isActive","CDATA",TrueFalse); - - sql = "SELECT isReadWrite FROM AD_Window_Access WHERE AD_Window_ID="+ window_id +" and AD_Role_ID=?"; - String isReadWrite = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isReadWrite","CDATA",isReadWrite); - - return atts; - } - - public static AttributesImpl createprocessaccessBinding( AttributesImpl atts, int process_id, int role_id) - { - String sql = null; - String name = null; - atts.clear(); - - sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; - name = DB.getSQLValueString(null,sql,process_id); - atts.addAttribute("","","processname","CDATA",name); - - sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; - name = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","rolename","CDATA",name); - - sql = "SELECT isActive FROM AD_Process_Access WHERE AD_Process_ID="+ process_id +" and AD_Role_ID=?"; - String TrueFalse = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isActive","CDATA",TrueFalse); - - sql = "SELECT isReadWrite FROM AD_Process_Access WHERE AD_Process_ID="+ process_id +" and AD_Role_ID=?"; - String isReadWrite = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isReadWrite","CDATA",isReadWrite); - - return atts; - } - - public static AttributesImpl createformaccessBinding( AttributesImpl atts, int form_id, int role_id) - { - String sql = null; - String name = null; - atts.clear(); - - sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?"; - name = DB.getSQLValueString(null,sql,form_id); - atts.addAttribute("","","formname","CDATA",name); - - sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; - name = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","rolename","CDATA",name); - - sql = "SELECT isActive FROM AD_Form_Access WHERE AD_Form_ID="+ form_id +" and AD_Role_ID=?"; - String TrueFalse = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isActive","CDATA",TrueFalse); - - sql = "SELECT isReadWrite FROM AD_Form_Access WHERE AD_Form_ID="+ form_id +" and AD_Role_ID=?"; - String isReadWrite = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isReadWrite","CDATA",isReadWrite); - - return atts; - - } - - public static AttributesImpl createworkflowaccessBinding( AttributesImpl atts, int workflow_id, int role_id) - { - String sql = null; - String name = null; - atts.clear(); - - sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?"; - name = DB.getSQLValueString(null,sql,workflow_id); - atts.addAttribute("","","workflowname","CDATA",name); - - sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; - name = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","rolename","CDATA",name); - - sql = "SELECT isActive FROM AD_Workflow_Access WHERE AD_Workflow_ID="+ workflow_id +" and AD_Role_ID=?"; - String TrueFalse = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isActive","CDATA",TrueFalse); - - sql = "SELECT isReadWrite FROM AD_Workflow_Access WHERE AD_Workflow_ID="+ workflow_id +" and AD_Role_ID=?"; - String isReadWrite = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isReadWrite","CDATA",isReadWrite); - - return atts; - } - - public static AttributesImpl createtaskaccessBinding( AttributesImpl atts, int task_id, int role_id) - { - String sql = null; - String name = null; - atts.clear(); - - sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?"; - name = DB.getSQLValueString(null,sql,task_id); - atts.addAttribute("","","taskname","CDATA",name); - - sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; - name = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","rolename","CDATA",name); - - sql = "SELECT isActive FROM AD_Task_Access WHERE AD_Task_ID="+ task_id +" and AD_Role_ID=?"; - String TrueFalse = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isActive","CDATA",TrueFalse); - - sql = "SELECT isReadWrite FROM AD_Task_Access WHERE AD_Task_ID="+ task_id +" and AD_Role_ID=?"; - String isReadWrite = DB.getSQLValueString(null,sql,role_id); - atts.addAttribute("","","isReadWrite","CDATA",isReadWrite); - return atts; - } - - public static AttributesImpl createreflistBinding( AttributesImpl atts, X_AD_Ref_List m_Ref_List) - { - String sql = null; - String name = null; - atts.clear(); - if (m_Ref_List.getAD_Ref_List_ID ()> 0 ){ - sql = "SELECT Name FROM AD_Ref_List WHERE AD_Ref_List_ID=?"; - name = DB.getSQLValueString(null,sql,m_Ref_List.getAD_Ref_List_ID ()); - } - if (name != null ) - atts.addAttribute("","","ADReflistNameID","CDATA",name); - else - atts.addAttribute("","","ADReflistNameID","CDATA",""); - if (m_Ref_List.getAD_Reference_ID()> 0 ){ - sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; - name = DB.getSQLValueString(null,sql,m_Ref_List.getAD_Reference_ID()); - } - if (name != null ) - atts.addAttribute("","","ADRefenceNameID","CDATA",name); - else - atts.addAttribute("","","ADRefenceNameID","CDATA",""); - atts.addAttribute("","","Description","CDATA",(m_Ref_List.getDescription () != null ? m_Ref_List.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Ref_List.getEntityType () != null ? m_Ref_List.getEntityType ():"")); - atts.addAttribute("","","Name","CDATA",(m_Ref_List.getName () != null ? m_Ref_List.getName ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Ref_List.isActive()== true ? "true":"false")); - //atts.addAttribute("","","ValidFrom","CDATA",(m_Ref_List.getValidFrom ().toGMTString() != null ? m_Ref_List.getValidFrom().toGMTString():"")); - //atts.addAttribute("","","ValidTo","CDATA",(m_Ref_List.getValidTo ().toGMTString() != null ? m_Ref_List.getValidTo().toGMTString():"")); - atts.addAttribute("","","Value","CDATA",(m_Ref_List.getValue () != null ? m_Ref_List.getValue ():"")); - return atts; - } - - public AttributesImpl createreferencetableBinding( AttributesImpl atts, int reference_ID) - { - atts.clear(); - String name = null; - String sql = null; - String sql1 = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID= " + reference_ID; - - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql1, get_TrxName()); - try { - ResultSet rs = pstmt.executeQuery(); - while (rs.next()){ - - if (reference_ID > 0 ){ - sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; - name = DB.getSQLValueString(null,sql,reference_ID); - atts.addAttribute("","","ADRefenceNameID","CDATA",name); - } - else - atts.addAttribute("","","ADRefenceNameID","CDATA",""); - - if (rs.getInt("AD_Table_ID")> 0 ){ - sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; - name = DB.getSQLValueString(null,sql,rs.getInt("AD_Table_ID")); - atts.addAttribute("","","ADTableNameID","CDATA",name); - } - else - atts.addAttribute("","","ADTableNameID","CDATA",""); - - if (rs.getInt("AD_Display") > 0 ){ - sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,rs.getInt("AD_Display")); - atts.addAttribute("","","ADDisplay","CDATA",name);} - else - atts.addAttribute("","","ADDisplay","CDATA",""); - - if (rs.getInt("AD_Key")> 0 ){ - sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,rs.getInt("AD_Key")); - atts.addAttribute("","","Key","CDATA",name); - } - else - atts.addAttribute("","","Key","CDATA",""); - atts.addAttribute("","","EntityType","CDATA",(rs.getString("EntityType") != null ? rs.getString("EntityType"):"")); - atts.addAttribute("","","IsValueDisplayed","CDATA",(rs.getString("IsValueDisplayed").compareTo("Y")==0 ? "Y":"N")); - atts.addAttribute("","","OrderByClause","CDATA",(rs.getString("OrderByClause") != null ? rs.getString("OrderByClause"):"")); - atts.addAttribute("","","isActive","CDATA",(rs.getString("isActive").compareTo("Y")==0 ? "Y":"N")); - atts.addAttribute("","","WhereClause","CDATA",(rs.getString("WhereClause") != null ? rs.getString("WhereClause"):"")); - - } - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - - } - finally - { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; - } - return atts; - } - - - public static AttributesImpl createPrintformatBinding( AttributesImpl atts, X_AD_PrintFormat m_Printformat) - { - String sql = null; - String name = null; - atts.clear(); - if (m_Printformat.getAD_ReportView_ID()> 0 ){ - sql = "SELECT Name FROM AD_ReportView WHERE AD_ReportView_ID=?"; - name = DB.getSQLValueString(null,sql,m_Printformat.getAD_ReportView_ID()); - atts.addAttribute("","","ADReportviewnameID","CDATA",name);} - else - atts.addAttribute("","","ADReportviewnameID","CDATA",""); - - if (m_Printformat.getAD_Table_ID()> 0 ){ - sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; - name = DB.getSQLValueString(null,sql,m_Printformat.getAD_Table_ID()); - atts.addAttribute("","","ADTableNameID","CDATA",name);} - else - atts.addAttribute("","","ADTableNameID","CDATA",""); - - if (m_Printformat.getAD_PrintTableFormat_ID()> 0 ){ - sql = "SELECT Name FROM AD_PrintTableFormat WHERE AD_PrintTableFormat_ID=?"; - name = DB.getSQLValueString(null,sql,m_Printformat.getAD_PrintTableFormat_ID()); - atts.addAttribute("","","ADPrintTableFormatID","CDATA",name);} - else - atts.addAttribute("","","ADPrintTableFormatID","CDATA",""); - - if (m_Printformat.getAD_PrintColor_ID()> 0 ){ - sql = "SELECT Name FROM AD_PrintColor WHERE AD_PrintColor_ID=?"; - name = DB.getSQLValueString(null,sql,m_Printformat.getAD_PrintColor_ID()); - atts.addAttribute("","","ADPrintColorID","CDATA",name);} - else - atts.addAttribute("","","ADPrintColorID","CDATA",""); - - if (m_Printformat.getAD_PrintFont_ID()> 0 ){ - sql = "SELECT Name FROM AD_PrintFont WHERE AD_PrintFont_ID=?"; - name = DB.getSQLValueString(null,sql,m_Printformat.getAD_PrintFont_ID()); - atts.addAttribute("","","ADPrintFontID","CDATA",name);} - else - atts.addAttribute("","","ADPrintFontID","CDATA",""); - - if (m_Printformat.getAD_PrintPaper_ID()> 0 ){ - sql = "SELECT Name FROM AD_PrintPaper WHERE AD_PrintPaper_ID=?"; - name = DB.getSQLValueString(null,sql,m_Printformat.getAD_PrintPaper_ID()); - atts.addAttribute("","","ADPrintPaperID","CDATA",name);} - else - atts.addAttribute("","","ADPrintPaperID","CDATA",""); - - atts.addAttribute("","","Description","CDATA",(m_Printformat.getDescription () != null ? m_Printformat.getDescription ():"")); - atts.addAttribute("","","Name","CDATA",(m_Printformat.getName () != null ? m_Printformat.getName ():"")); - atts.addAttribute("","","PrinterName","CDATA",(m_Printformat.getPrinterName() != null ? m_Printformat.getPrinterName ():"")); - atts.addAttribute("","","FooterMargin","CDATA",""+m_Printformat.getFooterMargin()); - atts.addAttribute("","","HeaderMargin","CDATA",""+m_Printformat.getHeaderMargin()); - atts.addAttribute("","","CreateCopy","CDATA",(m_Printformat.getCreateCopy() != null ? m_Printformat.getCreateCopy ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Printformat.isActive()== true ? "true":"false")); - atts.addAttribute("","","isTableBased","CDATA",(m_Printformat.isTableBased()== true ? "true":"false")); - atts.addAttribute("","","isForm","CDATA",(m_Printformat.isForm()== true ? "true":"false")); - atts.addAttribute("","","isStandardHeader","CDATA",(m_Printformat.isStandardHeaderFooter()== true ? "true":"false")); - atts.addAttribute("","","isDefault","CDATA",(m_Printformat.isDefault()== true ? "true":"false")); - return atts; - } - - public static AttributesImpl createPrintformatItemBinding( AttributesImpl atts, X_AD_PrintFormatItem m_PrintformatItem) - { - String sql = null; - String name = null; - atts.clear(); - if (m_PrintformatItem.getAD_PrintFormat_ID()> 0 ){ - sql = "SELECT Name FROM AD_PrintFormat WHERE AD_PrintFormat_ID=?"; - name = DB.getSQLValueString(null,sql,m_PrintformatItem.getAD_PrintFormat_ID()); - atts.addAttribute("","","ADPrintFormatNameID","CDATA",name);} - else - atts.addAttribute("","","ADPrintFormatNameID","CDATA",""); - - if (m_PrintformatItem.getAD_PrintFormatChild_ID()> 0 ){ - sql = "SELECT Name FROM AD_PrintFormat WHERE AD_PrintFormat_ID=?"; - name = DB.getSQLValueString(null,sql,m_PrintformatItem.getAD_PrintFormatChild_ID()); - atts.addAttribute("","","ADPrintFormatChildNameID","CDATA",name);} - else - atts.addAttribute("","","ADPrintFormatChildNameID","CDATA",""); - - if (m_PrintformatItem.getAD_Column_ID()> 0 ){ - sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,m_PrintformatItem.getAD_Column_ID()); - atts.addAttribute("","","ADColumnNameID","CDATA",name);} - else - atts.addAttribute("","","ADColumnNameID","CDATA",""); - - if (m_PrintformatItem.getAD_Column_ID()> 0 ){ - sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?"; - int tableID = DB.getSQLValue(null, sql,m_PrintformatItem.getAD_Column_ID()); - sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; - name = DB.getSQLValueString(null, sql,tableID); - atts.addAttribute("","","ADTableNameID","CDATA",name);} - else - atts.addAttribute("","","ADTableNameID","CDATA",""); - - - - if (m_PrintformatItem.getAD_PrintGraph_ID()> 0 ){ - sql = "SELECT Name FROM AD_PrintGraph WHERE AD_PrintGraph_ID=?"; - name = DB.getSQLValueString(null,sql,m_PrintformatItem.getAD_PrintGraph_ID()); - atts.addAttribute("","","ADPrintGraphID","CDATA",name);} - else - atts.addAttribute("","","ADPrintGraphID","CDATA",""); - - if (m_PrintformatItem.getAD_PrintColor_ID()> 0 ){ - sql = "SELECT Name FROM AD_PrintColor WHERE AD_PrintColor_ID=?"; - name = DB.getSQLValueString(null,sql,m_PrintformatItem.getAD_PrintColor_ID()); - atts.addAttribute("","","ADPrintColorID","CDATA",name);} - else - atts.addAttribute("","","ADPrintColorID","CDATA",""); - - if (m_PrintformatItem.getAD_PrintFont_ID()> 0 ){ - sql = "SELECT Name FROM AD_PrintFont WHERE AD_PrintFont_ID=?"; - name = DB.getSQLValueString(null,sql,m_PrintformatItem.getAD_PrintFont_ID()); - atts.addAttribute("","","ADPrintFontID","CDATA",name);} - else - atts.addAttribute("","","ADPrintFontID","CDATA",""); - - atts.addAttribute("","","PrintName","CDATA",(m_PrintformatItem.getPrintName () != null ? m_PrintformatItem.getPrintName ():"")); - atts.addAttribute("","","Name","CDATA",(m_PrintformatItem.getName () != null ? m_PrintformatItem.getName ():"")); - atts.addAttribute("","","PrintAreaType","CDATA",(m_PrintformatItem.getPrintAreaType() != null ? m_PrintformatItem.getPrintAreaType ():"")); - atts.addAttribute("","","SeqNo","CDATA",""+m_PrintformatItem.getSeqNo()); - atts.addAttribute("","","PrintFormatType","CDATA",m_PrintformatItem.getPrintFormatType()); - atts.addAttribute("","","XSpace","CDATA",(""+m_PrintformatItem.getXSpace())); - atts.addAttribute("","","YSpace","CDATA",(""+m_PrintformatItem.getYSpace())); - atts.addAttribute("","","Xposition","CDATA",(""+m_PrintformatItem.getXPosition())); - atts.addAttribute("","","Yposition","CDATA",(""+m_PrintformatItem.getYPosition())); - atts.addAttribute("","","MaxWidth","CDATA",(""+m_PrintformatItem.getMaxWidth())); - atts.addAttribute("","","MaxHieght","CDATA",(""+m_PrintformatItem.getMaxHeight())); - atts.addAttribute("","","SortNo","CDATA",(""+m_PrintformatItem.getSortNo())); - atts.addAttribute("","","FieldAlignmentType","CDATA",(m_PrintformatItem.getFieldAlignmentType() != null ? m_PrintformatItem.getFieldAlignmentType ():"")); - atts.addAttribute("","","LineAlignmentType","CDATA",(m_PrintformatItem.getLineAlignmentType() != null ? m_PrintformatItem.getLineAlignmentType ():"")); - atts.addAttribute("","","ImageURL","CDATA",(m_PrintformatItem.getImageURL() != null ? m_PrintformatItem.getImageURL ():"")); - atts.addAttribute("","","BelowColumn","CDATA",(""+m_PrintformatItem.getBelowColumn())); - atts.addAttribute("","","RunningTotalLines","CDATA",(""+m_PrintformatItem.getRunningTotalLines())); - atts.addAttribute("","","PrintNameSuffix","CDATA",(m_PrintformatItem.getPrintNameSuffix() != null ? m_PrintformatItem.getPrintNameSuffix ():"")); - atts.addAttribute("","","ArcDiameter","CDATA",""+m_PrintformatItem.getArcDiameter()); - atts.addAttribute("","","LineWidth","CDATA",""+m_PrintformatItem.getLineWidth()); - atts.addAttribute("","","ShapeType","CDATA",m_PrintformatItem.getShapeType() != null ? m_PrintformatItem.getShapeType():""); - atts.addAttribute("","","isActive","CDATA",(m_PrintformatItem.isActive()== true ? "true":"false")); - atts.addAttribute("","","isPrinted","CDATA",(m_PrintformatItem.isPrinted()== true ? "true":"false")); - atts.addAttribute("","","isRelativePosition","CDATA",(m_PrintformatItem.isRelativePosition()== true ? "true":"false")); - atts.addAttribute("","","isNextLine","CDATA",(m_PrintformatItem.isNextLine()== true ? "true":"false")); - atts.addAttribute("","","isHeightOneLine","CDATA",(m_PrintformatItem.isHeightOneLine()== true ? "true":"false")); - atts.addAttribute("","","isOrderBy","CDATA",(m_PrintformatItem.isOrderBy()== true ? "true":"false")); - atts.addAttribute("","","isGroupBy","CDATA",(m_PrintformatItem.isGroupBy()== true ? "true":"false")); - atts.addAttribute("","","isPageBreak","CDATA",(m_PrintformatItem.isPageBreak()== true ? "true":"false")); - atts.addAttribute("","","isSummarized","CDATA",(m_PrintformatItem.isSummarized()== true ? "true":"false")); - atts.addAttribute("","","isImageIsAttached","CDATA",(m_PrintformatItem.isImageIsAttached()== true ? "true":"false")); - atts.addAttribute("","","isAveraged","CDATA",(m_PrintformatItem.isAveraged()== true ? "true":"false")); - atts.addAttribute("","","isCounted","CDATA",(m_PrintformatItem.isCounted()== true ? "true":"false")); - atts.addAttribute("","","isSetNLPosition","CDATA",(m_PrintformatItem.isSetNLPosition()== true ? "true":"false")); - atts.addAttribute("","","isSuppressNull","CDATA",(m_PrintformatItem.isSuppressNull()== true ? "true":"false")); - atts.addAttribute("","","isFixedWidth","CDATA",(m_PrintformatItem.isFixedWidth()== true ? "true":"false")); - atts.addAttribute("","","isNextPage","CDATA",(m_PrintformatItem.isNextPage()== true ? "true":"false")); - atts.addAttribute("","","isMaxCalc","CDATA",(m_PrintformatItem.isMaxCalc()== true ? "true":"false")); - atts.addAttribute("","","isMinCalc","CDATA",(m_PrintformatItem.isMinCalc()== true ? "true":"false")); - atts.addAttribute("","","isRunningTotal","CDATA",(m_PrintformatItem.isRunningTotal()== true ? "true":"false")); - atts.addAttribute("","","isVarianceCalc","CDATA",(m_PrintformatItem.isVarianceCalc()== true ? "true":"false")); - atts.addAttribute("","","isDeviationCalc","CDATA",(m_PrintformatItem.isDeviationCalc()== true ? "true":"false")); - - return atts; - } - - public static AttributesImpl createreportviewBinding( AttributesImpl atts, X_AD_ReportView m_Reportview) - { - String sql = null; - String name = null; - atts.clear(); - - if (m_Reportview.getAD_ReportView_ID()> 0 ){ - sql = "SELECT Name FROM AD_ReportView WHERE AD_ReportView_ID=?"; - name = DB.getSQLValueString(null,sql,m_Reportview.getAD_ReportView_ID()); - atts.addAttribute("","","ADReportviewnameID","CDATA",name);} - else - atts.addAttribute("","","ADReportviewnameID","CDATA",""); - - if (m_Reportview.getAD_Table_ID()> 0 ){ - sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; - name = DB.getSQLValueString(null,sql,m_Reportview.getAD_Table_ID()); - atts.addAttribute("","","ADTableNameID","CDATA",name);} - else - atts.addAttribute("","","ADTableNameID","CDATA",""); - - atts.addAttribute("","","Description","CDATA",(m_Reportview.getDescription () != null ? m_Reportview.getDescription ():"")); - atts.addAttribute("","","EntityType","CDATA",(m_Reportview.getEntityType () != null ? m_Reportview.getEntityType ():"")); - atts.addAttribute("","","Name","CDATA",(m_Reportview.getName () != null ? m_Reportview.getName ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Reportview.isActive()== true ? "true":"false")); - atts.addAttribute("","","OrderByClause","CDATA",(m_Reportview.getOrderByClause () != null ? m_Reportview.getOrderByClause ():"")); - atts.addAttribute("","","WhereClause","CDATA",(m_Reportview.getWhereClause () != null ? m_Reportview.getWhereClause ():"")); - return atts; - } - - public static AttributesImpl createreportviewcolBinding( AttributesImpl atts, X_AD_ReportView_Col m_Reportview_Col) - { - String sql = null; - String name = null; - atts.clear(); - if (m_Reportview_Col.getAD_Column_ID()> 0 ){ - sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null,sql,m_Reportview_Col.getAD_Column_ID()); - atts.addAttribute("","","ADColumnNameID","CDATA",name);} - else - atts.addAttribute("","","ADColumnNameID","CDATA",""); - - if (m_Reportview_Col.getAD_ReportView_ID()> 0 ){ - sql = "SELECT Name FROM AD_Reference WHERE AD_Reportview_ID=?"; - name = DB.getSQLValueString(null,sql,m_Reportview_Col.getAD_ReportView_ID()); - atts.addAttribute("","","ADReportviewnameID","CDATA",name);} - else - atts.addAttribute("","","ADColumnNameID","CDATA",""); - - if (m_Reportview_Col.getAD_ReportView_Col_ID()> 0 ){ - sql = "SELECT Name FROM AD_Reference WHERE AD_ReportView_Col_ID=?"; - name = DB.getSQLValueString(null,sql,m_Reportview_Col.getAD_ReportView_Col_ID()); - atts.addAttribute("","","ADReportViewColID","CDATA",name);} - else - atts.addAttribute("","","ADColumnNameID","CDATA",""); - - atts.addAttribute("","","FunctionColumn","CDATA",(m_Reportview_Col.getFunctionColumn () != null ? m_Reportview_Col.getFunctionColumn ():"")); - atts.addAttribute("","","isActive","CDATA",(m_Reportview_Col.isActive()== true ? "true":"false")); - atts.addAttribute("","","isGroupFunction","CDATA",(m_Reportview_Col.isGroupFunction()== true ? "true":"false")); - return atts; - } - - public void CopyFile (String sourceName, String copyName ) { + public void copyFile (String sourceName, String copyName ) { InputStream source; // Stream for reading from the source file. OutputStream copy; // Stream for writing the copy. boolean force; // This is set to true if the "-f" option @@ -3603,5 +659,11 @@ else { System.out.println(e.toString()); } } + + + @Override + public Properties getCtx() { + return localContext != null ? localContext : super.getCtx(); + } } // PackOut diff --git a/base/src/org/adempiere/pipo/PackRoll.java b/base/src/org/adempiere/pipo/PackRoll.java index 105a6d81f5..36ca81a842 100644 --- a/base/src/org/adempiere/pipo/PackRoll.java +++ b/base/src/org/adempiere/pipo/PackRoll.java @@ -23,8 +23,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.logging.*; import org.compiere.util.DB; diff --git a/base/src/org/adempiere/pipo/exception/DatabaseAccessException.java b/base/src/org/adempiere/pipo/exception/DatabaseAccessException.java new file mode 100644 index 0000000000..8947da4d1b --- /dev/null +++ b/base/src/org/adempiere/pipo/exception/DatabaseAccessException.java @@ -0,0 +1,21 @@ +package org.adempiere.pipo.exception; + +public class DatabaseAccessException extends RuntimeException { + + public DatabaseAccessException() { + super(); + } + + public DatabaseAccessException(String message, Throwable cause) { + super(message, cause); + } + + public DatabaseAccessException(String message) { + super(message); + } + + public DatabaseAccessException(Throwable cause) { + super(cause); + } + +} diff --git a/base/src/org/adempiere/pipo/exception/POSaveFailedException.java b/base/src/org/adempiere/pipo/exception/POSaveFailedException.java new file mode 100644 index 0000000000..0df4f59092 --- /dev/null +++ b/base/src/org/adempiere/pipo/exception/POSaveFailedException.java @@ -0,0 +1,20 @@ +package org.adempiere.pipo.exception; + +public class POSaveFailedException extends RuntimeException { + + public POSaveFailedException() { + super(); + } + + public POSaveFailedException(String message, Throwable cause) { + super(message, cause); + } + + public POSaveFailedException(String message) { + super(message); + } + + public POSaveFailedException(Throwable cause) { + super(cause); + } +} diff --git a/base/src/org/adempiere/pipo/handler/CodeSnipitElementHandler.java b/base/src/org/adempiere/pipo/handler/CodeSnipitElementHandler.java new file mode 100644 index 0000000000..8af1715876 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/CodeSnipitElementHandler.java @@ -0,0 +1,244 @@ +/****************************************************************************** + * 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.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.compiere.Adempiere; +import org.compiere.model.MSequence; +import org.compiere.model.X_AD_Package_Exp_Detail; +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 CodeSnipitElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + log.info(elementValue); + Object_Status = "Update"; + Attributes atts = element.attributes; + String releaseNumber = atts.getValue("ReleaseNo"); + //Check Release Number + if(Adempiere.MAIN_VERSION.equals(releaseNumber)||releaseNumber.equals("all")){ + String sourceName = atts.getValue("filename"); + String targetDirectory = atts.getValue("filedir"); + String oldCode = atts.getValue("oldcode"); + String newCode = atts.getValue("newcode"); + + int idDetail=0; + InputStream source; // Stream for reading from the source file. + OutputStream copy; // Stream for writing the copy. + File currentDirectory = new File("."); + + String packagePath=null; + String sourcePath=null; + + //get compiere-all directory + try { + packagePath = currentDirectory.getCanonicalPath(); + File parentDirectory = new File(packagePath); + + while (!parentDirectory.getName().equals("packages")){ + parentDirectory = parentDirectory.getParentFile(); + } + parentDirectory = parentDirectory.getParentFile(); + sourcePath = parentDirectory.getCanonicalPath(); + } catch (IOException e1) { + System.out.println("Can't find compiere-all directory."); + } + + + // Create backup directory if required + File backupDir = new File(packagePath+File.separator+"backup"+File.separator); + if (!backupDir.exists()){ + boolean success = (new File(packagePath+File.separator+"backup"+File.separator)).mkdirs(); + if (!success) { + log.info("Backup directory creation failed"); + } + } + + //Correct target directory for proper file seperator + String fullDirectory = sourcePath+targetDirectory; + String targetDirectoryModified=null; + String fileDate = null; + char slash1 = '\\'; + char slash2 = '/'; + if (File.separator.equals("/")) + targetDirectoryModified = fullDirectory.replace(slash1,slash2); + else + targetDirectoryModified = fullDirectory.replace(slash2,slash1); + + File file = new File(targetDirectoryModified+sourceName); + log.info(targetDirectoryModified+sourceName); + //TODO: derived force from user parameter + boolean force = true; + // check to see if overwrites are allowed + if (file.exists() && force == false) { + System.out.println( + "Output file exists. Use the -f option to replace it."); + return; + } + //backup file to package directory + else if (file.exists() && force == true) { + Object_Status = "Update"; + log.info("Target Backup:"+targetDirectoryModified+sourceName); + source = OpenInputfile(targetDirectoryModified+sourceName); + SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssSSSSZ"); + Date today = new Date(); + fileDate = formatter_file.format(today); + copy = OpenOutputfile(packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName); + log.info("Source Backup:"+packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName); + copyFile (source,copy); + log.info("Backup Complete"); + } + + int success = readReplace(targetDirectoryModified+sourceName, oldCode, newCode); + +// Record in log + int idBackup = MSequence.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx)); + if (success != -1){ + try { + idDetail = record_log (ctx, 1, sourceName,"codesnipit", 0,0, Object_Status,sourceName,0); + } catch (SAXException e) { + log.info ("setfile:"+e); + } + } + else{ + try { + idDetail = record_log (ctx, 0, sourceName,"codesnipit", 0,0, Object_Status,sourceName,0); + } catch (SAXException e) { + log.info ("setfile:"+e); + } + } + //Record in transaction file + 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_PACKAGE_IMP_ORG_DIR, AD_PACKAGE_IMP_BCK_DIR)" ) + .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( ", '" + targetDirectoryModified+sourceName ) + .append( "', '" + packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName ) + .append( "')"); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) + log.info("Insert to import backup failed"); + + } + } + + + /** + * Find and replace code + * + * @param file name + * @param old string + * @param new string + * + */ + public static int readReplace(String fname, String oldPattern, String replPattern){ + String line; + StringBuffer sb = new StringBuffer(); + + try { + + FileInputStream fis = new FileInputStream(fname); + BufferedReader reader=new BufferedReader ( new InputStreamReader(fis)); + while((line = reader.readLine()) != null) { + line = line.replaceAll(oldPattern, replPattern); + System.err.println(line); + sb.append(line+"\n"); + } + reader.close(); + BufferedWriter out=new BufferedWriter ( new FileWriter(fname)); + out.write(sb.toString()); + out.close(); + } + catch (Throwable e) { + System.err.println("error replacing codesnipit "+e); + return -1; + } + return 0; + } + + + public void endElement(Properties ctx, Element element) + throws SAXException { + } + + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + String FileDir = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory); + String FileName = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_FileName); + String OldCode = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old); + String NewCode = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New); + String ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); + AttributesImpl atts = new AttributesImpl(); + createSnipitBinding(atts, FileDir, FileName, OldCode, NewCode, ReleaseNo); + document.startElement("","","codesnipit",atts); + document.endElement("","","codesnipit"); + } + + private AttributesImpl createSnipitBinding( AttributesImpl atts, String FileDir, String FileName, String OldCode, String NewCode, String ReleaseNo) + { + atts.clear(); + atts.addAttribute("","","filedir","CDATA",FileDir); + atts.addAttribute("","","filename","CDATA",FileName); + String preOldCode = OldCode.toString(); + String preNewCode = NewCode.toString(); + String modOldCode = preOldCode.replaceAll("\\$","\\\\\\$").replaceAll("\\.","\\\\.") + .replaceAll("\\^","\\\\^").replaceAll("\\(","\\\\(").replaceAll("\\)","\\\\)") + .replaceAll("\\[","\\\\[").replaceAll("\\/","\\\\/").replaceAll("\\+","\\\\+") + .replaceAll("\\*","\\\\*").replaceAll("\\|","\\\\|"); + String modNewCode = preNewCode.replaceAll("\\$","\\\\\\$").replaceAll("\\.","\\\\.") + .replaceAll("\\^","\\\\^").replaceAll("\\(","\\\\(").replaceAll("\\)","\\\\)") + .replaceAll("\\[","\\\\[").replaceAll("\\/","\\\\/").replaceAll("\\+","\\\\+") + .replaceAll("\\*","\\\\*").replaceAll("\\|","\\\\|"); + atts.addAttribute("","","oldcode","CDATA",modOldCode); + atts.addAttribute("","","newcode","CDATA",modNewCode); + atts.addAttribute("","","ReleaseNo","CDATA",ReleaseNo); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/ColumnElementHandler.java b/base/src/org/adempiere/pipo/handler/ColumnElementHandler.java new file mode 100644 index 0000000000..6cfa32252e --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/ColumnElementHandler.java @@ -0,0 +1,466 @@ +/****************************************************************************** + * 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.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.MColumn; +import org.compiere.model.MTable; +import org.compiere.model.X_AD_Column; +import org.compiere.model.X_AD_Element; +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 ColumnElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("ColumnName")); + int success = 0; + String entitytype = atts.getValue("EntityType"); + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 + && getUpdateMode(ctx).compareTo("true") == 0) { + String columnName = atts.getValue("ColumnName"); + + int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", atts + .getValue("ADTableNameID")); + int id = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", + columnName, "AD_Table", tableid); + MColumn m_Column = new MColumn(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Column", m_Column); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + m_Column.setColumnName(columnName); + + String Name = atts.getValue("ADProcessNameID"); + id = get_IDWithColumn(ctx, "AD_Process", "Name", Name); + m_Column.setAD_Process_ID(id); + Name = atts.getValue("ADReferenceNameID"); + // log.info("Column Name1 ->"+Name); + // log.info("Database Name ->"+m_DatabaseType); + // log.info("Column Name2 ->"+Name); + id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name); + m_Column.setAD_Reference_ID(id); + // log.info("Column ID ->"+id); + Name = atts.getValue("ADTableNameID"); + id = get_IDWithColumn(ctx, "AD_Table", "TableName", Name); + m_Column.setAD_Table_ID(id); + + Name = atts.getValue("ADValRuleNameID"); + id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name); + m_Column.setAD_Val_Rule_ID(id); + Name = atts.getValue("ADReferenceNameValueID"); + id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name); + m_Column.setAD_Reference_Value_ID(id); + m_Column.setCallout(atts.getValue("Callout")); + m_Column.setColumnSQL(atts.getValue("ColumnSQL")); + + m_Column.setColumnName(atts.getValue("ColumnName")); + m_Column.setDefaultValue(atts.getValue("DefaultValue")); + m_Column.setDescription(atts.getValue("Description").replaceAll( + "'", "''").replaceAll(",", "")); + m_Column.setEntityType(atts.getValue("EntityType")); + + if (Integer.parseInt(atts.getValue("FieldLength")) > 0) + m_Column.setFieldLength(Integer.parseInt(atts + .getValue("FieldLength"))); + m_Column.setHelp(atts.getValue("Help").replaceAll("'", "''") + .replaceAll(",", "")); + m_Column.setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() : true); + m_Column.setIsAlwaysUpdateable((Boolean.valueOf(atts + .getValue("isAlwaysUpdateable")).booleanValue())); + // m_Column.setIsEncrypted(atts.getValue("isEncrypted")); + m_Column.setIsIdentifier((Boolean.valueOf(atts + .getValue("isIdentifier")).booleanValue())); + m_Column.setIsKey((Boolean.valueOf(atts.getValue("isKey")) + .booleanValue())); + m_Column.setIsMandatory((Boolean.valueOf(atts + .getValue("isMandatory")).booleanValue())); + + m_Column.setIsParent((Boolean.valueOf(atts.getValue("isParent")) + .booleanValue())); + m_Column.setIsSelectionColumn((Boolean.valueOf(atts + .getValue("isSelectionColumn")).booleanValue())); + m_Column.setIsSyncDatabase(atts.getValue("getIsSyncDatabase")); + + m_Column.setIsTranslated((Boolean.valueOf(atts + .getValue("isTranslated")).booleanValue())); + m_Column.setIsUpdateable((Boolean.valueOf(atts + .getValue("isUpdateable")).booleanValue())); + m_Column.setName(atts.getValue("Name")); + m_Column.setReadOnlyLogic(atts.getValue("ReadOnlyLogic")); + + if (Integer.parseInt(atts.getValue("SeqNo")) > 0) + m_Column.setSeqNo(Integer.parseInt(atts.getValue("SeqNo"))); + m_Column.setVFormat(atts.getValue("VFormat")); + if (atts.getValue("ValueMax") != null) + m_Column.setValueMax(atts.getValue("ValueMax")); + if (atts.getValue("ValueMin") != null) + m_Column.setValueMin(atts.getValue("ValueMin")); + if (atts.getValue("Version") != null) + m_Column.setVersion(new BigDecimal(atts.getValue("Version"))); + + // Setup Element. + id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", m_Column + .getColumnName()); + X_AD_Element adElement = new X_AD_Element(ctx, id, getTrxName(ctx)); + + String Object_Status_col = Object_Status; + if (adElement.getAD_Element_ID() == 0) { + // Object_Status = "New"; + adElement.setColumnName(m_Column.getColumnName()); + adElement.setEntityType(m_Column.getEntityType()); + adElement.setPrintName(m_Column.getColumnName()); + + adElement.setName(m_Column.getColumnName()); + if (adElement.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Column.getName(), "Element", adElement + .getAD_Element_ID(), AD_Backup_ID, "New", + "AD_Element", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Element")); + } else { + record_log(ctx, 0, m_Column.getName(), "Element", adElement + .getAD_Element_ID(), AD_Backup_ID, "New", + "AD_Element", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Element")); + } + } + + Object_Status = Object_Status_col; + m_Column.setAD_Element_ID(adElement.getAD_Element_ID()); + + boolean recreateColumn = (m_Column.is_new() + || m_Column.is_ValueChanged("AD_Reference_ID") + || m_Column.is_ValueChanged("FieldLength") + || m_Column.is_ValueChanged("ColumnName") || m_Column + .is_ValueChanged("IsMandatory")); + + // changed default ?? + // m_Column.is_ValueChanged("DefaultValue") doesn't work well with + // nulls + if (!recreateColumn) { + String oldDefault = (String) m_Column + .get_ValueOld("DefaultValue"); + String newDefault = (String) m_Column.get_Value("DefaultValue"); + if (oldDefault != null && oldDefault.length() == 0) + oldDefault = null; + if (newDefault != null && newDefault.length() == 0) + newDefault = null; + if ((oldDefault == null && newDefault != null) + || (oldDefault != null && newDefault == null)) { + recreateColumn = true; + } else if (oldDefault != null && newDefault != null) { + if (!oldDefault.equals(newDefault)) + recreateColumn = true; + } + } + + // Don't create database column for virtual columns + // Don't create columns by default, just if getIsSyncDatabase='Y' + if (recreateColumn) { + String sync = atts.getValue("getIsSyncDatabase"); + if (m_Column.isVirtualColumn() || sync == null + || (!sync.equals("Y"))) + recreateColumn = false; + } + + if (m_Column.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Column.getName(), "Column", m_Column + .get_ID(), AD_Backup_ID, Object_Status, "AD_Column", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Column")); + } else { + record_log(ctx, 0, m_Column.getName(), "Column", m_Column + .get_ID(), AD_Backup_ID, Object_Status, "AD_Column", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Column")); + throw new POSaveFailedException("Column"); + } + + if (recreateColumn) { + success = createcolumn(ctx, m_Column); + + if (success == 1) { + record_log(ctx, 1, m_Column.getColumnName(), "dbColumn", + m_Column.get_ID(), 0, Object_Status, atts.getValue( + "ADTableNameID").toUpperCase(), + get_IDWithColumn(ctx, "AD_Table", "TableName", atts + .getValue("ADTableNameID").toUpperCase())); + } else { + record_log(ctx, 0, m_Column.getColumnName(), "dbColumn", + m_Column.get_ID(), 0, Object_Status, atts.getValue( + "ADTableNameID").toUpperCase(), + get_IDWithColumn(ctx, "AD_Table", "TableName", atts + .getValue("ADTableNameID").toUpperCase())); + throw new DatabaseAccessException("CreateColumn"); + } + } + } + } + + /** + * Check if column exists in database and modify. If not create column. + * + * @param tablename + * @param columnname + * @param v_AD_Reference_ID + * @param v_FieldLength + * @param v_DefaultValue + * @param v_IsMandatory + * + */ + private int createcolumn(Properties ctx, MColumn column) { + MTable table = new MTable(ctx, column.getAD_Table_ID(), getTrxName(ctx)); + if (table.isView()) + return 0; + + int no = 0; + + String sql = null; + ResultSet rst = null; + ResultSet rsc = null; + try { + // Find Column in Database + DatabaseMetaData md = DB.getConnectionRO().getMetaData(); + String catalog = DB.getDatabase().getCatalog(); + String schema = DB.getDatabase().getSchema(); + String tableName = table.getTableName(); + String columnName = column.getColumnName(); + if (DB.isOracle()) { + tableName = tableName.toUpperCase(); + columnName = columnName.toUpperCase(); + } else if (DB.isPostgreSQL()) { + tableName = tableName.toLowerCase(); + columnName = columnName.toLowerCase(); + } + + rst = md.getTables(catalog, schema, tableName, + new String[] { "TABLE" }); + if (!rst.next()) { + // table doesn't exist + sql = table.getSQLCreate(); + } else { + // + rsc = md.getColumns(catalog, schema, tableName, columnName); + if (rsc.next()) { + // update existing column + boolean notNull = DatabaseMetaData.columnNoNulls == rsc + .getInt("NULLABLE"); + sql = column.getSQLModify(table, + column.isMandatory() != notNull); + } else { + // No existing column + sql = column.getSQLAdd(table); + } + rsc.close(); + rsc = null; + } + + rst.close(); + rst = null; + log.info(sql); + + if (sql.indexOf(DB.SQLSTATEMENT_SEPARATOR) == -1) { + no = DB.executeUpdate(sql, false, getTrxName(ctx)); + } else { + String statements[] = sql.split(DB.SQLSTATEMENT_SEPARATOR); + for (int i = 0; i < statements.length; i++) { + int count = DB.executeUpdate(statements[i], false, + getTrxName(ctx)); + no += count; + } + } + + } catch (SQLException e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + if (rsc != null) { + try { + rsc.close(); + } catch (SQLException e1) { + } + rsc = null; + } + if (rst != null) { + try { + rst.close(); + } catch (SQLException e1) { + } + rst = null; + } + return 0; + } + + // postgres requires commit on DDL (ALTER,CREATE) + if (DB.isPostgreSQL()) { + try { + DB.commit(true, getTrxName(ctx)); + } catch (SQLException e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + return 0; + } + } + + return 1; + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Column_ID = Env.getContextAsInt(ctx, + X_AD_Column.COLUMNNAME_AD_Column_ID); + AttributesImpl atts = new AttributesImpl(); + X_AD_Column m_Column = new X_AD_Column(ctx, AD_Column_ID, + getTrxName(ctx)); + createColumnBinding(atts, m_Column); + document.startElement("", "", "column", atts); + document.endElement("", "", "column"); + } + + private AttributesImpl createColumnBinding(AttributesImpl atts, + X_AD_Column m_Column) { + String sql = null; + String name = null; + atts.clear(); + if (m_Column.getAD_Column_ID() > 0) { + sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null, sql, m_Column.getAD_Column_ID()); + atts.addAttribute("", "", "ADColumnNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADColumnNameID", "CDATA", ""); + if (m_Column.getAD_Process_ID() > 0) { + sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; + name = DB.getSQLValueString(null, sql, m_Column.getAD_Process_ID()); + atts.addAttribute("", "", "ADProcessNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADProcessNameID", "CDATA", ""); + if (m_Column.getAD_Element_ID() > 0) { + sql = "SELECT Name FROM AD_Element WHERE AD_Element_ID=?"; + name = DB.getSQLValueString(null, sql, m_Column.getAD_Element_ID()); + atts.addAttribute("", "", "ADElementNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADElementNameID", "CDATA", ""); + if (m_Column.getAD_Reference_ID() > 0) { + sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; + name = DB.getSQLValueString(null, sql, m_Column + .getAD_Reference_ID()); + atts.addAttribute("", "", "ADReferenceNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADReferenceNameID", "CDATA", ""); + if (m_Column.getAD_Reference_Value_ID() > 0) { + sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; + name = DB.getSQLValueString(null, sql, m_Column + .getAD_Reference_Value_ID()); + atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", name); + } else + atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", ""); + if (m_Column.getAD_Table_ID() > 0) { + sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; + name = DB.getSQLValueString(null, sql, m_Column.getAD_Table_ID()); + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADTableNameID", "CDATA", ""); + if (m_Column.getAD_Val_Rule_ID() > 0) { + sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?"; + name = DB + .getSQLValueString(null, sql, m_Column.getAD_Val_Rule_ID()); + atts.addAttribute("", "", "ADValRuleNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADValRuleNameID", "CDATA", ""); + atts.addAttribute("", "", "Callout", "CDATA", + (m_Column.getCallout() != null ? m_Column.getCallout() : "")); + atts.addAttribute("", "", "ColumnSQL", "CDATA", (m_Column + .getColumnSQL() != null ? m_Column.getColumnSQL() : "")); + atts.addAttribute("", "", "ColumnName", "CDATA", (m_Column + .getColumnName() != null ? m_Column.getColumnName() : "")); + atts.addAttribute("", "", "DefaultValue", "CDATA", (m_Column + .getDefaultValue() != null ? m_Column.getDefaultValue() : "")); + atts.addAttribute("", "", "Description", "CDATA", (m_Column + .getDescription() != null ? m_Column.getDescription() : "")); + atts.addAttribute("", "", "EntityType", "CDATA", (m_Column + .getEntityType() != null ? m_Column.getEntityType() : "")); + atts.addAttribute("", "", "FieldLength", "CDATA", (m_Column + .getFieldLength() > 0 ? "" + m_Column.getFieldLength() : "0")); + atts.addAttribute("", "", "Help", "CDATA", + (m_Column.getHelp() != null ? m_Column.getHelp() : "")); + atts.addAttribute("", "", "isAlwaysUpdateable", "CDATA", (m_Column + .isAlwaysUpdateable() == true ? "true" : "false")); + // atts.addAttribute("","","isEncrypted","CDATA",(m_Column.getIsEncrypted()== + // true ? "true":"false")); + atts.addAttribute("", "", "isIdentifier", "CDATA", (m_Column + .isIdentifier() == true ? "true" : "false")); + atts.addAttribute("", "", "isKey", "CDATA", + (m_Column.isKey() == true ? "true" : "false")); + atts.addAttribute("", "", "isMandatory", "CDATA", (m_Column + .isMandatory() == true ? "true" : "false")); + atts.addAttribute("", "", "isParent", "CDATA", + (m_Column.isParent() == true ? "true" : "false")); + atts.addAttribute("", "", "isSelectionColumn", "CDATA", (m_Column + .isSelectionColumn() == true ? "true" : "false")); + atts.addAttribute("", "", "isActive", "CDATA", + (m_Column.isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "isTranslated", "CDATA", (m_Column + .isTranslated() == true ? "true" : "false")); + atts.addAttribute("", "", "isUpdateable", "CDATA", (m_Column + .isUpdateable() == true ? "true" : "false")); + atts.addAttribute("", "", "Name", "CDATA", + (m_Column.getName() != null ? m_Column.getName() : "")); + atts.addAttribute("", "", "getIsSyncDatabase", "CDATA", (m_Column + .getIsSyncDatabase() != null ? m_Column.getIsSyncDatabase() + : "")); + atts + .addAttribute("", "", "ReadOnlyLogic", "CDATA", (m_Column + .getReadOnlyLogic() != null ? m_Column + .getReadOnlyLogic() : "")); + atts.addAttribute("", "", "SeqNo", "CDATA", + (m_Column.getSeqNo() > 0 ? "" + m_Column.getSeqNo() : "0")); + atts.addAttribute("", "", "VFormat", "CDATA", + (m_Column.getVFormat() != null ? m_Column.getVFormat() : "")); + atts.addAttribute("", "", "ValueMax", "CDATA", + (m_Column.getValueMax() != null ? m_Column.getValueMax() : "")); + atts.addAttribute("", "", "ValueMin", "CDATA", + (m_Column.getValueMin() != null ? m_Column.getValueMin() : "")); + atts.addAttribute("", "", "Version", "CDATA", + (m_Column.getVersion() != null ? "" + m_Column.getVersion() + : "0.0")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/DataElementHandler.java b/base/src/org/adempiere/pipo/handler/DataElementHandler.java new file mode 100644 index 0000000000..1dfa07f0af --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/DataElementHandler.java @@ -0,0 +1,389 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +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.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.GenericPO; +import org.adempiere.pipo.IDFinder; +import org.compiere.model.POInfo; +import org.compiere.model.X_AD_Package_Exp_Detail; +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 DataElementHandler extends AbstractElementHandler { + + private GenericPO genericPO = null; + int AD_Backup_ID = -1; + String Object_Status = null; + String d_tablename = null; + + private DataRowElementHandler rowHandler = new DataRowElementHandler(); + private DataColumnElementHandler columnHandler = new DataColumnElementHandler(); + + public DataElementHandler() { + } + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + if (elementValue.equals("adempieredata") || elementValue.equals("data")) { + log.info(elementValue); + if (atts.getValue("clientname") != null) { + int AD_Client_ID = IDFinder.get_ID("AD_Client", atts.getValue("clientname"), getClientId(ctx), getTrxName(ctx)); + Env.setContext(ctx, "AD_Client_ID", AD_Client_ID); + log.info("adempieredata: client set to "+AD_Client_ID+" "+atts.getValue("clientname")); + } + } + else if (elementValue.equals("dtable")) { + log.info(elementValue+" "+atts.getValue("name")); + d_tablename = atts.getValue("name"); + } + // row element, adempieredata + else if (elementValue.equals("drow")) { + rowHandler.startElement(ctx, element); + } + // column element, adempieredata + else if (elementValue.equals("dcolumn")) { + columnHandler.startElement(ctx, element); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + if (elementValue.equals("drow")) { + rowHandler.endElement(ctx, element); + } + } + + class DataRowElementHandler 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"); + ctx.setProperty("adempieredataTable_ID", String.valueOf(get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename))); + // 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(ctx, id, getTrxName(ctx)); + if (id > 0){ + AD_Backup_ID = copyRecord(ctx,d_tablename,genericPO); + Object_Status = "Update"; + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + } + } + // keyXname and lookupkeyXname. + else { + String sql = "select * from "+d_tablename; + String whereand = " where"; + String t_tablename = null; + String CURRENT_KEY = "key1name"; + if (!atts.getValue(CURRENT_KEY).equals("")) { + t_tablename = atts.getValue(CURRENT_KEY).substring(0, atts.getValue(CURRENT_KEY).length()-3); + sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY); + whereand = " and"; + } + CURRENT_KEY = "key2name"; + if (!atts.getValue(CURRENT_KEY).equals("")) { + t_tablename = atts.getValue(CURRENT_KEY).substring(0, atts.getValue(CURRENT_KEY).length()-3); + sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY); + whereand = " and"; + } + // Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value + try { + PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) { + Object_Status = "Update"; + genericPO = new GenericPO(ctx, rs, getTrxName(ctx)); + rs.close(); + pstmt.close(); + pstmt = null; + } + else { + genericPO = new GenericPO(ctx, 0, getTrxName(ctx)); + rs.close(); + pstmt.close(); + pstmt = null; + Object_Status = "New"; + // set keyXname. + CURRENT_KEY = "key1name"; + if (!atts.getValue(CURRENT_KEY).equals("")) { + t_tablename = atts.getValue(CURRENT_KEY).substring(0, atts.getValue(CURRENT_KEY).length()-3); + genericPO.setValueNoCheck(atts.getValue(CURRENT_KEY), atts.getValue("lookup"+CURRENT_KEY)); + } + CURRENT_KEY = "key2name"; + if (!atts.getValue(CURRENT_KEY).equals("")) { + t_tablename = atts.getValue(CURRENT_KEY).substring(0, atts.getValue(CURRENT_KEY).length()-3); + genericPO.setValueNoCheck(atts.getValue(CURRENT_KEY), atts.getValue("lookup"+CURRENT_KEY)); + } + } + + } + catch (Exception e) { + log.info ("keyXname attribute. init from rs error."+e); + } + } + // reset Table ID for GenericPO. + ctx.setProperty("adempieredataTable_ID", "0"); + // for debug GenericPO. + if (false) { + POInfo poInfo = POInfo.getPOInfo(ctx, get_ID(ctx, "AD_Table", d_tablename)); + if (poInfo == null) + log.info("poInfo is null."); + for (int i = 0; i < poInfo.getColumnCount(); i++) { + log.info(d_tablename+" column: "+poInfo.getColumnName(i)); + } + } + // globalqss: set AD_Client_ID to the client setted in adempieredata + if (getClientId(ctx) > 0 && genericPO.getAD_Client_ID() != getClientId(ctx)) + genericPO.setValue("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.setValue("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.setValue((String)thisValue.get(0), (String)thisValue.get(1)); + else if (((String)(thisValue.get(2))).equals("Integer")) + genericPO.setValue((String)thisValue.get(0), Integer.valueOf((String)thisValue.get(1))); + else if (((String)(thisValue.get(2))).equals("Boolean")) + genericPO.setValue((String)thisValue.get(0), new Boolean(((String)thisValue.get(1)).equals("true") ? true : false)); + } + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + if (genericPO != null) { + if (genericPO.save(getTrxName(ctx))== true) + record_log (ctx, 1, genericPO.get_TableName(),"Data", genericPO.get_ID(),AD_Backup_ID, Object_Status,d_tablename,get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename)); + else + record_log (ctx, 0, genericPO.get_TableName(),"Data", genericPO.get_ID(),AD_Backup_ID, Object_Status,d_tablename,get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename)); + + genericPO = null; + } + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + } + + } + + class DataColumnElementHandler 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 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); + 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 = ?"); + String isKey = DB.getSQLValueString(getTrxName(ctx), sql.toString(),id); + if (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")) { + 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.setValue(atts.getValue("name").toString(), atts.getValue("value").toString()); + } + else if (atts.getValue("class").equals("Number") || atts.getValue("class").equals("Amount") + || atts.getValue("class").equals("Quantity")|| atts.getValue("class").equals("Costs+Prices")){ + genericPO.setValue(atts.getValue("name").toString(), new BigDecimal(atts.getValue("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.setValue(atts.getValue("name").toString(), Integer.valueOf(atts.getValue("value"))); + } + else if (atts.getValue("class").equals("Boolean")) { + genericPO.setValue(atts.getValue("name"), new Boolean(atts.getValue("value").equals("true") ? true : false)); + } + else if (atts.getValue("class").equals("Date") || atts.getValue("class").equals("Date+Time") + || atts.getValue("class").equals("Time")) { + genericPO.setValue(atts.getValue("name").toString(), Timestamp.valueOf(atts.getValue("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.setValue(atts.getValue("name"), new Integer(getIDbyName(ctx, m_tablename, atts.getValue("lookupname")))); + } + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + } + + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + String sql = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); + int table_id = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID); + Statement stmt = DB.createStatement(); + AttributesImpl atts = new AttributesImpl(); + document.startElement("","","data",atts); + try { + ResultSet rs = stmt.executeQuery(sql); + ResultSetMetaData meta = rs.getMetaData(); + int columns = meta.getColumnCount(); + int i = 1; + String col_Name = null; + String sql1 = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; + String table_Name = DB.getSQLValueString(null,sql1,table_id); + atts.clear(); + atts.addAttribute("","","name","CDATA",table_Name); + document.startElement("","","dtable",atts); + while (rs.next()){ + atts.clear(); + int key1 = 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 " + + "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; + } + else if (cName.toUpperCase().equals(col_Name) && key1 == 1 ){ + atts.addAttribute("","","key2name","CDATA",cName); + atts.addAttribute("","","lookupkey2name","CDATA",""+rs.getObject(col_Name)); + key1 = 2; + } + } + } + atts.addAttribute("","","name","CDATA",nameatts); + if ( key1 == 0 ){ + atts.addAttribute("","","key1name","CDATA",""); + atts.addAttribute("","","lookupkey1name","CDATA",""); + key1 = 1; + } + if ( key1 == 1 ){ + atts.addAttribute("","","key2name","CDATA",""); + atts.addAttribute("","","lookupkey2name","CDATA",""); + } + document.startElement("","","drow",atts); + for (i=1 ;i <= columns;i++){ + atts.clear(); + col_Name = meta.getColumnName(i).toUpperCase(); + String sql2 = "Select A.ColumnName, B.Name " + + "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"; + PreparedStatement pstmt = null; + try + { + pstmt = DB.prepareStatement(sql2, getTrxName(ctx)); + pstmt.setString(1, col_Name); + pstmt.setInt(2, table_id); + ResultSet rs1 = pstmt.executeQuery(); + while (rs1.next()){ + //added 9/3/05 + 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)); + + 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); + document.endElement("","","dcolumn"); + } + } + rs1.close(); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.log(Level.SEVERE,"getData", e); + } + } + document.endElement("","","drow"); + } + rs.close(); + stmt.close(); + stmt = null; + document.endElement("","","dtable"); + } + + catch (Exception e) { + log.log(Level.SEVERE,"getData", e); + } + + document.endElement("","","data"); + + } + +} diff --git a/base/src/org/adempiere/pipo/handler/DistFileElementHandler.java b/base/src/org/adempiere/pipo/handler/DistFileElementHandler.java new file mode 100644 index 0000000000..d6f65ac079 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/DistFileElementHandler.java @@ -0,0 +1,201 @@ +/****************************************************************************** + * 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.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.compiere.Adempiere; +import org.compiere.model.MSequence; +import org.compiere.model.X_AD_Package_Exp_Detail; +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 DistFileElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + Attributes atts = element.attributes; + log.info(elementValue+" "+atts.getValue("name")); + + String releaseNumber = atts.getValue("ReleaseNo"); + //log.info(atts.getValue("ReleaseNo")); + //log.info(Compiere.MAIN_VERSION); + //Check Release Number + if(releaseNumber==null||Adempiere.MAIN_VERSION.equals(releaseNumber)||releaseNumber.equals("all")){ + String sourceName = atts.getValue("name"); + String sourceDirectory = atts.getValue("sourceDirectory"); + String targetDirectory = atts.getValue("targetDirectory"); + + Object_Status = "New"; + int idDetail=0; + InputStream source; // Stream for reading from the source file. + OutputStream copy; // Stream for writing the copy. + + String packagePath=null; + String sourcePath=null; + + //get compiere-all directory + try { + packagePath = getPackageDirectory(ctx); + File parentDirectory = new File(packagePath); + while (!parentDirectory.getName().equals("packages")){ + parentDirectory = parentDirectory.getParentFile(); + } + parentDirectory = parentDirectory.getParentFile(); + sourcePath = parentDirectory.getCanonicalPath(); + } catch (IOException e1) { + System.out.println("Can't find compiere-all directory."); + } + + + // Create backup directory if required + File backupDir = new File(packagePath+File.separator+"backup"+File.separator); + if (!backupDir.exists()){ + boolean success = (new File(packagePath+File.separator+"backup"+File.separator)).mkdirs(); + if (!success) { + log.info("Backup directory creation failed"); + } + } + + + //Correct target directory for proper file seperator + String fullDirectory = sourcePath+targetDirectory; + String targetDirectoryModified=null; + char slash1 = '\\'; + char slash2 = '/'; + if (File.separator.equals("/")) + targetDirectoryModified = fullDirectory.replace(slash1,slash2); + else + targetDirectoryModified = fullDirectory.replace(slash2,slash1); + + File file = new File(targetDirectoryModified+sourceName); + //TODO: derive force from user parameter + boolean force = true; + String fileDate = null; + //check to see if overwrites are allowed + if (file.exists() && force == false) { + System.out.println( + "Output file exists. Use the -f option to replace it."); + return; + } + //backup file to package directory + else if (file.exists() && force == true) { + Object_Status = "Update"; + log.info("Target Backup:"+targetDirectoryModified+sourceName); + source = OpenInputfile(targetDirectoryModified+sourceName); + SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssSSSSZ"); + Date today = new Date(); + fileDate = formatter_file.format(today); + copy = OpenOutputfile(packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName); + log.info("Source Backup:"+packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName); + copyFile (source,copy); + log.info("Backup Complete"); + } + +// Correct dist directory for proper file seperator + String distDirectoryModified=null; + if (File.separator.equals("/")) + distDirectoryModified = sourceDirectory.replace(slash1,slash2); + else + distDirectoryModified = sourceDirectory.replace(slash2,slash1); + source = OpenInputfile(packagePath+distDirectoryModified+sourceName); + +// Create Target directory if required + File targetDir = new File(targetDirectoryModified); + if (!targetDir.exists()){ + boolean success = (new File(targetDirectoryModified)).mkdirs(); + if (!success) { + log.info("Target directory creation failed"); + } + } + copy = OpenOutputfile(targetDirectoryModified+sourceName); + //Copy File + int success = copyFile (source,copy); + //Record in log + int idBackup = MSequence.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx)); + if (success != -1){ + try { + idDetail = record_log (ctx, 1, sourceName,"file", 0,0, Object_Status,sourceName,0); + } catch (SAXException e) { + log.info ("setfile:"+e); + } + } + else{ + try { + idDetail = record_log (ctx, 0, sourceName,"file", 0,0, Object_Status,sourceName,0); + } catch (SAXException e) { + log.info ("setfile:"+e); + } + } + //Record in transaction file + 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_PACKAGE_IMP_ORG_DIR, AD_PACKAGE_IMP_BCK_DIR)" ) + .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( ", '" + targetDirectoryModified+sourceName ) + .append( "', '" + packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName ) + .append( "')"); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) + log.info("Insert to import backup failed"); + + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + String FileName = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_FileName); + String Source_Directory = Env.getContext(ctx, "Source_Directory"); + String Target_Directory = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory); + String ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute("","","name","CDATA",FileName); + atts.addAttribute("","","sourceDirectory","CDATA",Source_Directory); + atts.addAttribute("","","targetDirectory","CDATA",Target_Directory); + atts.addAttribute("","","ReleaseNo","CDATA",ReleaseNo); + document.startElement("","","distfile",atts); + document.endElement("","","distfile"); + } + +} diff --git a/base/src/org/adempiere/pipo/handler/DynValRuleElementHandler.java b/base/src/org/adempiere/pipo/handler/DynValRuleElementHandler.java new file mode 100644 index 0000000000..3439ff5d14 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/DynValRuleElementHandler.java @@ -0,0 +1,128 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.compiere.model.X_AD_Package_Exp_Detail; +import org.compiere.model.X_AD_Val_Rule; +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 DynValRuleElementHandler 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 entitytype = atts.getValue("EntityType"); + if (entitytype.equals("U") || entitytype.equals("D") && getUpdateMode(ctx).equals("true")) { + String name = atts.getValue("Name"); + int id = get_IDWithColumn(ctx, "AD_Val_Rule", "name", name); + + X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0){ + AD_Backup_ID = copyRecord(ctx, "AD_Val_Rule",m_ValRule); + Object_Status = "Update"; + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + } + m_ValRule.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); + m_ValRule.setEntityType(atts.getValue("EntityType")); + m_ValRule.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); + m_ValRule.setName(name); + m_ValRule.setType(atts.getValue("Type")); + m_ValRule.setCode(atts.getValue("Code")); + if (m_ValRule.save(getTrxName(ctx)) == true){ + record_log (ctx, 1, m_ValRule.getName(),"Task", m_ValRule.get_ID(),AD_Backup_ID, Object_Status,"AD_Val_Rule",get_IDWithColumn(ctx, "AD_Val_Rule", "Name", "AD_Val_Rule")); + } + else{ + record_log (ctx, 0, m_ValRule.getName(),"Task", m_ValRule.get_ID(),AD_Backup_ID, Object_Status,"AD_Val_Rule",get_IDWithColumn(ctx, "AD_Val_Rule", "Name", "AD_Val_Rule")); + } + } + + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Val_Rule_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID); + String sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID= " + AD_Val_Rule_ID; + AttributesImpl atts = new AttributesImpl(); + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement (sql, getTrxName(ctx)); + + try { + + ResultSet rs = pstmt.executeQuery(); + + while (rs.next()) + { + X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule (ctx, AD_Val_Rule_ID, null); + createDynamicValidationRuleBinding(atts,m_ValRule); + document.startElement("","","dynvalrule",atts); + document.endElement("","","dynvalrule"); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e){ + log.log(Level.SEVERE,"getProcess", e); + } + finally{ + try { + if (pstmt != null) + pstmt.close (); + } + catch (Exception e){} + pstmt = null; + } + + } + + private AttributesImpl createDynamicValidationRuleBinding( AttributesImpl atts, X_AD_Val_Rule m_ValRule) + { + atts.clear(); + atts.addAttribute("","","Name","CDATA",(m_ValRule.getName () != null ? m_ValRule.getName ():"")); + //FIXME: may not need this I guess + //atts.addAttribute("","","AccessLevel","CDATA",(m_ValRule.getAccessLevel () != null ? m_ValRule.getAccessLevel ():"")); + atts.addAttribute("","","Code","CDATA",(m_ValRule.getCode() != null ? m_ValRule.getCode ():"")); + atts.addAttribute("","","Description","CDATA",(m_ValRule.getDescription () != null ? m_ValRule.getDescription ():"")); + atts.addAttribute("","","EntityType","CDATA",(m_ValRule.getEntityType () != null ? m_ValRule.getEntityType ():"")); + atts.addAttribute("","","Type","CDATA",(m_ValRule.getType () != null ? m_ValRule.getType ():"")); + atts.addAttribute("","","isActive","CDATA",(m_ValRule.isActive()== true ? "true":"false")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/FieldElementHandler.java b/base/src/org/adempiere/pipo/handler/FieldElementHandler.java new file mode 100644 index 0000000000..8fdcaed58c --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/FieldElementHandler.java @@ -0,0 +1,191 @@ +/****************************************************************************** + * 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.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 { + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + log.info(elementValue+" "+atts.getValue("Name")); + String entitytype = atts.getValue("EntityType"); + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && getUpdateMode(ctx).compareTo("true") == 0) { + String name = atts.getValue("Name"); + String tabname = atts.getValue("ADTabNameID"); + String colname = atts.getValue("ADColumnNameID"); +// log.info("Column Name ->"+colname); +// log.info("Database Name ->"+m_DatabaseType); + int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID")); + int windowid = get_ID(ctx, "AD_Window", atts.getValue("ADWindowNameID")); + //log.info("Column Name ->"+colname); + int columnid = get_IDWithMasterAndColumn (ctx, "AD_Column","ColumnName", colname, "AD_Table", tableid); + //log.info("ColumnID->"+columnid); + 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 = ?"); + int tabid = DB.getSQLValue(getTrxName(ctx), sqlB.toString (), tableid); + + if (tabid > 0 ) + { + + sqlB = new StringBuffer ("select AD_Field_ID from AD_Field where AD_Column_ID = "+columnid + + " 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(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); + m_Field.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); + m_Field.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); + m_Field.setSortNo(new BigDecimal(atts.getValue("SortNo"))); + m_Field.setDisplayLogic(atts.getValue("DisplayLogic")); + 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")); + } + 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")); + } + } + else + log.severe("Tab do not exist to field Name: "+ name); + + } + } + + 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); + 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():"")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/FormAccessElementHandler.java b/base/src/org/adempiere/pipo/handler/FormAccessElementHandler.java new file mode 100644 index 0000000000..ec8f522ee5 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/FormAccessElementHandler.java @@ -0,0 +1,137 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.compiere.model.X_AD_Form; +import org.compiere.model.X_AD_Role; +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 FormAccessElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + log.info(elementValue); + int roleid =0; + int formid =0; + StringBuffer sqlB = null; + Attributes atts = element.attributes; + if (atts.getValue("rolename")!=null){ + String name = atts.getValue("rolename"); + sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); + roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + if (atts.getValue("formname")!=null){ + String name = atts.getValue("formname"); + sqlB = new StringBuffer ("SELECT AD_Form_ID FROM AD_Process WHERE Name= ?"); + formid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + sqlB = new StringBuffer ("SELECT count(*) FROM AD_Form_Access WHERE AD_Role_ID=? and AD_Form_ID=?"); + int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,formid); + String Object_Status = null; + int AD_Backup_ID = -1; + if (count>0){ + Object_Status = "Update"; + sqlB = new StringBuffer ("UPDATE AD_Form_Access ") + .append( "SET isActive = '" + atts.getValue("isActive") ) + .append( "', isReadWrite = '" + atts.getValue("isReadWrite") ) + .append( "' WHERE AD_Role_ID = " + roleid ) + .append( " and AD_Form_ID = " + formid ); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) { + log.info("Update to form access failed"); + throw new DatabaseAccessException("Update to form access failed"); + } + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + sqlB = new StringBuffer ("Insert INTO AD_Form_Access" + + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " + + "AD_Role_ID, AD_Form_ID, isActive, isReadWrite) " + + "VALUES(" + + " "+ Env.getAD_Client_ID(ctx) + + ", "+ Env.getAD_Org_ID(ctx) + + ", "+ Env.getAD_User_ID(ctx) + + ", "+ Env.getAD_User_ID(ctx) + + ", " + roleid + + ", " + formid + + ", '" + atts.getValue("isActive") + + "', '" + atts.getValue("isReadWrite")+"')"); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) { + log.info("Insert to form access failed"); + throw new DatabaseAccessException("Insert to form access failed"); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Form_ID = Env.getContextAsInt(ctx, X_AD_Form.COLUMNNAME_AD_Form_ID); + int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + AttributesImpl atts = new AttributesImpl(); + createFormAccessBinding(atts, AD_Form_ID, AD_Role_ID); + document.startElement("", "", "formaccess", atts); + document.endElement("", "", "formaccess"); + } + + private AttributesImpl createFormAccessBinding(AttributesImpl atts, + int form_id, int role_id) { + String sql = null; + String name = null; + atts.clear(); + + sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?"; + name = DB.getSQLValueString(null, sql, form_id); + atts.addAttribute("", "", "formname", "CDATA", name); + + sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; + name = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "rolename", "CDATA", name); + + sql = "SELECT isActive FROM AD_Form_Access WHERE AD_Form_ID=" + form_id + + " and AD_Role_ID=?"; + String TrueFalse = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isActive", "CDATA", TrueFalse); + + sql = "SELECT isReadWrite FROM AD_Form_Access WHERE AD_Form_ID=" + + form_id + " and AD_Role_ID=?"; + String isReadWrite = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isReadWrite", "CDATA", isReadWrite); + + return atts; + } + +} diff --git a/base/src/org/adempiere/pipo/handler/FormElementHandler.java b/base/src/org/adempiere/pipo/handler/FormElementHandler.java new file mode 100644 index 0000000000..5df622c610 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/FormElementHandler.java @@ -0,0 +1,110 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.compiere.model.MForm; +import org.compiere.model.X_AD_Form; +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 FormElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + log.info(elementValue+" "+atts.getValue("ADFormNameID")); + + String entitytype = atts.getValue("EntityType"); + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && getUpdateMode(ctx).compareTo("true") == 0 ) { + String name = atts.getValue("ADFormNameID"); + int id = get_ID(ctx, "AD_Form", name); + MForm m_Form = new MForm(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0){ + AD_Backup_ID = copyRecord(ctx, "AD_Form",m_Form); + Object_Status = "Update"; + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + } + m_Form.setClassname (atts.getValue("Classname")); + m_Form.setIsBetaFunctionality (Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue()); + m_Form.setAccessLevel(atts.getValue("AccessLevel")); + m_Form.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); + m_Form.setEntityType(atts.getValue("EntityType")); + m_Form.setHelp(atts.getValue("Help").replaceAll(",","")); + m_Form.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); + m_Form.setName(atts.getValue("Name")); + + if (m_Form.save(getTrxName(ctx)) == true){ + record_log (ctx, 1, m_Form.getName(),"Form", m_Form.get_ID(),AD_Backup_ID, Object_Status,"AD_Form",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Form")); + } + else{ + record_log (ctx, 0, m_Form.getName(),"Form", m_Form.get_ID(),AD_Backup_ID, Object_Status,"AD_Form",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Form")); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Form_ID = Env.getContextAsInt(ctx, "AD_Form_ID"); + X_AD_Form m_Form = new X_AD_Form (ctx, AD_Form_ID, null); + AttributesImpl atts = new AttributesImpl(); + createFormBinding(atts,m_Form); + document.startElement("","","form",atts); + document.endElement("","","form"); + } + + private AttributesImpl createFormBinding( AttributesImpl atts, X_AD_Form m_Form) + { + String sql = null; + String name = null; + atts.clear(); + if (m_Form.getAD_Form_ID()> 0 ){ + sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?"; + name = DB.getSQLValueString(null,sql,m_Form.getAD_Form_ID()); + } + if (name != null ) + atts.addAttribute("","","ADFormNameID","CDATA",name); + else + atts.addAttribute("","","ADFormNameID","CDATA",""); + atts.addAttribute("","","Classname","CDATA",(m_Form.getClassname () != null ? m_Form.getClassname ():"")); + atts.addAttribute("","","isBetaFunctionality","CDATA",(m_Form.isBetaFunctionality()== true ? "true":"false")); + atts.addAttribute("","","AccessLevel","CDATA",(m_Form.getAccessLevel () != null ? m_Form.getAccessLevel ():"")); + atts.addAttribute("","","Description","CDATA",(m_Form.getDescription () != null ? m_Form.getDescription ():"")); + atts.addAttribute("","","isActive","CDATA",(m_Form.isActive()== true ? "true":"false")); + atts.addAttribute("","","EntityType","CDATA",(m_Form.getEntityType () != null ? m_Form.getEntityType ():"")); + atts.addAttribute("","","Help","CDATA",(m_Form.getHelp() != null ? m_Form.getHelp():"")); + atts.addAttribute("","","Name","CDATA",(m_Form.getName() != null ? m_Form.getName():"")); + return atts; + } + +} diff --git a/base/src/org/adempiere/pipo/handler/ImpFormatElementHandler.java b/base/src/org/adempiere/pipo/handler/ImpFormatElementHandler.java new file mode 100644 index 0000000000..c76d04dfa5 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/ImpFormatElementHandler.java @@ -0,0 +1,169 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.X_AD_ImpFormat; +import org.compiere.model.X_AD_ImpFormat_Row; +import org.compiere.model.X_AD_Package_Exp_Detail; +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 ImpFormatElementHandler extends AbstractElementHandler { + + private ImpFormatRowElementHandler rowHandler = new ImpFormatRowElementHandler(); + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("Name")); + + int id = get_ID(ctx, "AD_ImpFormat", atts.getValue("Name")); + X_AD_ImpFormat m_ImpFormat = new X_AD_ImpFormat(ctx, id, + getTrxName(ctx)); + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_ImpFormat", m_ImpFormat); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + m_ImpFormat.setName(atts.getValue("Name")); + String name = atts.getValue("ADTableNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Table", "TableName", name); + if (id <= 0) { + element.defer = true; + return; + } + m_ImpFormat.setAD_Table_ID(id); + } + + m_ImpFormat.setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() : true); + m_ImpFormat + .setProcessing(atts.getValue("isProcessing") != null ? Boolean + .valueOf(atts.getValue("isProcessing")).booleanValue() + : true); + m_ImpFormat.setName(atts.getValue("Name")); + m_ImpFormat.setDescription(atts.getValue("Description")); + m_ImpFormat.setFormatType(atts.getValue("FormatType")); + if (m_ImpFormat.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_ImpFormat.getName(), "ImpFormat", m_ImpFormat + .get_ID(), AD_Backup_ID, Object_Status, "AD_ImpFormat", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_ImpFormat")); + } else { + record_log(ctx, 0, m_ImpFormat.getName(), "ImpFormat", m_ImpFormat + .get_ID(), AD_Backup_ID, Object_Status, "AD_ImpFormat", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_ImpFormat")); + throw new POSaveFailedException("ImpFormat"); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int import_id = Env.getContextAsInt(ctx, + X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID); + AttributesImpl atts = new AttributesImpl(); + X_AD_ImpFormat m_ImpFormat = new X_AD_ImpFormat(ctx, import_id, null); + atts = createImpFormatBinding(atts, m_ImpFormat); + + document.startElement("", "", "impformat", atts); + String sql = "SELECT * FROM AD_ImpFormat_Row WHERE AD_ImpFormat_ID= " + + import_id; + + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + createImpFormatRow(ctx, document, rs + .getInt("AD_ImpFormat_Row_ID")); + } + rs.close(); + pstmt.close(); + pstmt = null; + } catch (Exception e) { + log.log(Level.SEVERE, "ImpFormat", e); + throw new DatabaseAccessException("ImpFormat", e); + } finally { + try { + if (pstmt != null) + pstmt.close(); + } catch (Exception e) { + } + pstmt = null; + } + document.endElement("", "", "impformat"); + + } + + private void createImpFormatRow(Properties ctx, + TransformerHandler document, int AD_ImpFormat_Row_ID) + throws SAXException { + Env.setContext(ctx, X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID, + AD_ImpFormat_Row_ID); + rowHandler.create(ctx, document); + ctx.remove(X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID); + } + + private AttributesImpl createImpFormatBinding(AttributesImpl atts, + X_AD_ImpFormat m_ImpFormat) { + atts.clear(); + if (m_ImpFormat.getAD_Table_ID() > 0) { + String sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; + String name = DB.getSQLValueString(null, sql, m_ImpFormat + .getAD_Table_ID()); + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADTableNameID", "CDATA", ""); + + atts.addAttribute("", "", "Name", "CDATA", + (m_ImpFormat.getName() != null ? m_ImpFormat.getName() : "")); + atts.addAttribute("", "", "isActive", "CDATA", + (m_ImpFormat.isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "isProcessing", "CDATA", (m_ImpFormat + .isProcessing() == true ? "true" : "false")); + atts.addAttribute("", "", "Description", "CDATA", (m_ImpFormat + .getDescription() != null ? m_ImpFormat.getDescription() : "")); + atts.addAttribute("", "", "FormatType", "CDATA", (m_ImpFormat + .getFormatType() != null ? m_ImpFormat.getFormatType() : "")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/ImpFormatRowElementHandler.java b/base/src/org/adempiere/pipo/handler/ImpFormatRowElementHandler.java new file mode 100644 index 0000000000..840b0c30cb --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/ImpFormatRowElementHandler.java @@ -0,0 +1,163 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.X_AD_ImpFormat_Row; +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 ImpFormatRowElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + Attributes atts = element.attributes; + log.info(elementValue+" "+atts.getValue("Name")); + + int impformid = get_ID(ctx, "AD_ImpFormat", atts.getValue("ADImpFormatNameID")); + if (impformid <= 0) { + element.defer = true; + return; + } + + String name = atts.getValue("ADTableNameID"); + int tableid = 0; + if (name != null && name.trim().length() > 0) { + tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", name); + if (tableid <= 0) { + element.defer = true; + return; + } + + } + + name = atts.getValue("ADColumnNameID"); + int columnid = 0; + if (name != null && name.trim().length() > 0) { + columnid = get_IDWithMasterAndColumn (ctx, "AD_Column","ColumnName", name, "AD_Table", tableid); + if (columnid <= 0) { + element.defer = true; + return; + } + } + + StringBuffer sqlB = new StringBuffer ("SELECT AD_ImpFormat_Row_ID FROM AD_ImpFormat_Row WHERE AD_Column_ID=? and AD_ImpFormat_ID=?"); + int id = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),columnid,impformid); + X_AD_ImpFormat_Row m_ImpFormat_row = new X_AD_ImpFormat_Row(ctx, id, getTrxName(ctx)); + if (id > 0){ + AD_Backup_ID = copyRecord(ctx, "AD_ImpFormat",m_ImpFormat_row); + Object_Status = "Update"; + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + } + m_ImpFormat_row.setName(atts.getValue("Name")); + m_ImpFormat_row.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); + if (columnid > 0) + m_ImpFormat_row.setAD_Column_ID(columnid); + m_ImpFormat_row.setAD_ImpFormat_ID(impformid); + m_ImpFormat_row.setDataFormat(atts.getValue("DataFormat")); + m_ImpFormat_row.setDataType(atts.getValue("DataType")); + m_ImpFormat_row.setDecimalPoint(atts.getValue("DecimalPoint")); + m_ImpFormat_row.setDivideBy100(atts.getValue("isDivideBy100") != null ? Boolean.valueOf(atts.getValue("isDivideBy100")).booleanValue():true); + m_ImpFormat_row.setConstantValue(atts.getValue("ConstantValue")); + m_ImpFormat_row.setCallout(atts.getValue("Callout")); + m_ImpFormat_row.setEndNo(Integer.parseInt(atts.getValue("EndNo"))); + m_ImpFormat_row.setScript(atts.getValue("Script")); + m_ImpFormat_row.setSeqNo(Integer.parseInt(atts.getValue("SeqNo"))); + m_ImpFormat_row.setStartNo(Integer.parseInt(atts.getValue("StartNo"))); + if (m_ImpFormat_row.save(getTrxName(ctx)) == true){ + record_log (ctx, 1, m_ImpFormat_row.getName(),"ImpFormat", m_ImpFormat_row.get_ID(),AD_Backup_ID, Object_Status,"AD_ImpFormat",get_IDWithColumn(ctx, "AD_Table", "TableName", "m_ImpFormat_row")); + } + else{ + record_log (ctx, 0, m_ImpFormat_row.getName(),"ImpFormat", m_ImpFormat_row.get_ID(),AD_Backup_ID, Object_Status,"AD_ImpFormat",get_IDWithColumn(ctx, "AD_Table", "TableName", "m_ImpFormat_row")); + throw new POSaveFailedException("ImpFormatRow"); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_ImpFormat_Row_ID = Env.getContextAsInt(ctx, X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID); + X_AD_ImpFormat_Row m_ImpFormat_Row = new X_AD_ImpFormat_Row (ctx, AD_ImpFormat_Row_ID, getTrxName(ctx)); + AttributesImpl atts = new AttributesImpl(); + createImpFormatRowBinding(atts,m_ImpFormat_Row); + document.startElement("","","impformatrow",atts); + document.endElement("","","impformatrow"); + } + + private AttributesImpl createImpFormatRowBinding( AttributesImpl atts, X_AD_ImpFormat_Row m_ImpFormat_Row) + { + String sql = null; + String name = null; + atts.clear(); + if (m_ImpFormat_Row.getAD_ImpFormat_ID()> 0 ){ + sql = "SELECT Name FROM AD_ImpFormat WHERE AD_ImpFormat_ID=?"; + name = DB.getSQLValueString(null,sql,m_ImpFormat_Row.getAD_ImpFormat_ID()); + atts.addAttribute("","","ADImpFormatNameID","CDATA",name); + } + else + atts.addAttribute("","","ADImpFormatNameID","CDATA",""); + + if (m_ImpFormat_Row.getAD_Column_ID()> 0 ){ + sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null,sql,m_ImpFormat_Row.getAD_Column_ID()); + atts.addAttribute("","","ADColumnNameID","CDATA",name); + } + else + atts.addAttribute("","","ADColumnNameID","CDATA",""); + + if (m_ImpFormat_Row.getAD_Column_ID()> 0 ){ + sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?"; + int idTable = DB.getSQLValue(null, sql,m_ImpFormat_Row.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",""); + + atts.addAttribute("","","Name","CDATA",(m_ImpFormat_Row.getName () != null ? m_ImpFormat_Row.getName ():"")); + atts.addAttribute("","","SeqNo","CDATA",""+m_ImpFormat_Row.getSeqNo()); + atts.addAttribute("","","StartNo","CDATA",""+m_ImpFormat_Row.getStartNo()); + atts.addAttribute("","","EndNo","CDATA",""+m_ImpFormat_Row.getEndNo()); + atts.addAttribute("","","DataType","CDATA",(m_ImpFormat_Row.getDataType () != null ? m_ImpFormat_Row.getDataType():"")); + atts.addAttribute("","","DataFormat","CDATA",(m_ImpFormat_Row.getDataFormat () != null ? m_ImpFormat_Row.getDataFormat():"")); + atts.addAttribute("","","DecimalPoint","CDATA",(m_ImpFormat_Row.getDecimalPoint () != null ? m_ImpFormat_Row.getDecimalPoint():"")); + atts.addAttribute("","","isDivideBy100","CDATA",(m_ImpFormat_Row.isDivideBy100 ()== true ? "true":"false")); + atts.addAttribute("","","ConstantValue","CDATA",(m_ImpFormat_Row.getConstantValue() != null ? m_ImpFormat_Row.getConstantValue():"")); + atts.addAttribute("","","Callout","CDATA",(m_ImpFormat_Row.getCallout() != null ? m_ImpFormat_Row.getCallout():"")); + atts.addAttribute("","","Script","CDATA",(m_ImpFormat_Row.getScript() != null ? m_ImpFormat_Row.getScript():"")); + atts.addAttribute("","","isActive","CDATA",(m_ImpFormat_Row.isActive()== true ? "true":"false")); + + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/MenuElementHandler.java b/base/src/org/adempiere/pipo/handler/MenuElementHandler.java new file mode 100644 index 0000000000..9a23f4e911 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/MenuElementHandler.java @@ -0,0 +1,508 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.PackOut; +import org.compiere.model.MSequence; +import org.compiere.model.X_AD_Menu; +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 MenuElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("ADMenuNameID")); + // String entitytype = atts.getValue("EntityType"); + // if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 + // && m_UpdateMode == true ) { + + String name = null; + int idDetail = 0; + StringBuffer sqlB = null; + + name = atts.getValue("ADMenuNameID"); + int menuid = get_IDWithColumn(ctx, "AD_Menu", "Name", name); + X_AD_Menu m_Menu = new X_AD_Menu(ctx, menuid, getTrxName(ctx)); + if (menuid > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Menu", m_Menu); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + + m_Menu.setName(name); + name = atts.getValue("ADWindowNameID"); + if (name != null && name.trim().length() > 0) { + int id = get_IDWithColumn(ctx, "AD_Window", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Menu.setAD_Window_ID(id); + } + + name = atts.getValue("ADProcessNameID"); + if (name != null && name.trim().length() > 0) { + int id = get_IDWithColumn(ctx, "AD_Process", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Menu.setAD_Process_ID(id); + } + + name = atts.getValue("ADFormNameID"); + if (name != null && name.trim().length() > 0) { + int id = get_IDWithColumn(ctx, "AD_Form", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Menu.setAD_Form_ID(id); + } + + name = atts.getValue("ADTaskNameID"); + if (name != null && name.trim().length() > 0) { + int id = get_IDWithColumn(ctx, "AD_Task", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Menu.setAD_Task_ID(id); + } + + name = atts.getValue("ADWorkbenchNameID"); + if (name != null && name.trim().length() > 0) { + int id = get_IDWithColumn(ctx, "AD_Workbench", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Menu.setAD_Workbench_ID(id); + } + + name = atts.getValue("ADWorkflowNameID"); + if (name != null && name.trim().length() > 0) { + int id = get_IDWithColumn(ctx, "AD_Workflow", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Menu.setAD_Workflow_ID(id); + } + + String action = (atts.getValue("Action") != null ? atts + .getValue("Action") : " "); + if (action.compareTo(" ") > -1) + m_Menu.setAction(action); + m_Menu.setDescription(atts.getValue("Description") + .replaceAll("'", "''").replaceAll(",", "")); + m_Menu.setEntityType(atts.getValue("EntityType")); + m_Menu.setIsReadOnly(Boolean.valueOf(atts.getValue("isReadOnly")) + .booleanValue()); + m_Menu.setIsSOTrx(Boolean.valueOf(atts.getValue("isSOTrx")) + .booleanValue()); + m_Menu.setIsSummary(Boolean.valueOf(atts.getValue("isSummary")) + .booleanValue()); + m_Menu.setIsActive(Boolean.valueOf(atts.getValue("isActive")) + .booleanValue()); + if (m_Menu.save(getTrxName(ctx)) == true) { + try { + idDetail = record_log(ctx, 1, m_Menu.getName(), "Menu", m_Menu + .get_ID(), AD_Backup_ID, Object_Status, "AD_Menu", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Menu")); + } catch (SAXException e) { + log.info("setmenu:" + e); + } + } else { + try { + idDetail = record_log(ctx, 0, m_Menu.getName(), "Menu", m_Menu + .get_ID(), AD_Backup_ID, Object_Status, "AD_Menu", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Menu")); + } catch (SAXException e) { + log.info("setmenu:" + e); + } + } + name = atts.getValue("ADParentMenuNameID"); + int id = get_ID(ctx, "AD_Menu", name); + + String sql2 = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = 10" + + " AND Node_ID = " + menuid; + int countRecords = DB.getSQLValue(getTrxName(ctx), sql2); + if (countRecords > 0) { + StringBuffer sqlC = new StringBuffer( + "select * from AD_TREENODEMM where AD_Tree_ID = 10 and " + + " Node_ID =?"); + try { + PreparedStatement pstmt1 = DB.prepareStatement(sqlC.toString(), + getTrxName(ctx)); + pstmt1.setInt(1, menuid); + ResultSet rs1 = pstmt1.executeQuery(); + if (rs1.next()) { + + String colValue = null; + ResultSetMetaData meta = rs1.getMetaData(); + int columns = meta.getColumnCount(); + int tableID = get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_TreeNodeMM"); + + for (int q = 1; q <= columns; q++) { + + String col_Name = meta.getColumnName(q); + StringBuffer sql = new StringBuffer( + "SELECT AD_Column_ID FROM AD_column WHERE Upper(ColumnName) = '" + + col_Name + "' AND AD_Table_ID = ?"); + int columnID = DB.getSQLValue(getTrxName(ctx), sql + .toString(), tableID); + sql = new StringBuffer( + "SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = '" + + columnID + "'"); + int referenceID = DB.getSQLValue(getTrxName(ctx), sql + .toString()); + int idBackup = MSequence.getNextID(Env + .getAD_Client_ID(ctx), "AD_Package_Imp_Backup", + getTrxName(ctx)); + if (referenceID == 20 || referenceID == 28) + if (rs1.getObject(q).equals("Y")) + colValue = "true"; + else + colValue = "false"; + else + colValue = rs1.getObject(q).toString(); + + StringBuffer sqlD = new StringBuffer( + "Insert INTO AD_Package_Imp_Backup" + + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " + + "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," + + " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" + + "VALUES(" + " " + + Env.getAD_Client_ID(ctx) + + ", " + + Env.getAD_Org_ID(ctx) + + ", " + + Env.getAD_User_ID(ctx) + + ", " + + Env.getAD_User_ID(ctx) + + ", " + + idBackup + + ", " + + idDetail + + ", " + + getPackageImpId(ctx) + + ", " + + tableID + + ", " + + columnID + + ", " + + referenceID + + ", '" + colValue + "')"); + int no = DB.executeUpdate(sqlD.toString(), + getTrxName(ctx)); + if (no == -1) + log.info("Insert to import backup failed"); + } + + } + rs1.close(); + pstmt1.close(); + pstmt1 = null; + + } catch (Exception e) { + log.info("get_IDWithMasterID:" + e); + } + + sqlB = new StringBuffer("UPDATE AD_TREENODEMM ").append( + "SET Parent_ID = " + id).append( + " , SeqNo = " + atts.getValue("ADParentSeqno")).append( + " WHERE AD_Tree_ID = 10").append( + " AND Node_ID = " + m_Menu.getAD_Menu_ID()); + } else { + sqlB = new StringBuffer("Insert INTO AD_TREENODEMM").append( + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append( + "Parent_ID, SeqNo, AD_Tree_ID, Node_ID)").append( + "VALUES(0, 0, 0, 0, ").append( + id + "," + atts.getValue("ADParentSeqno") + ", 10, " + + m_Menu.getAD_Menu_ID() + ")"); + } + DB.executeUpdate(sqlB.toString(), getTrxName(ctx)); + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Menu_ID = Env.getContextAsInt(ctx, "AD_Menu_ID"); + X_AD_Menu m_Menu = new X_AD_Menu(ctx, AD_Menu_ID, null); + if (m_Menu.isSummary() == false) { + createApplication(ctx, document, AD_Menu_ID); + } else { + AttributesImpl atts = new AttributesImpl(); + createMenuBinding(atts, m_Menu); + document.startElement("", "", "menu", atts); + createModule(ctx, document, AD_Menu_ID); + document.endElement("", "", "menu"); + } + } + + private AttributesImpl createMenuBinding(AttributesImpl atts, + X_AD_Menu m_Menu) { + String sql = null; + String name = null; + atts.clear(); + if (m_Menu.getAD_Menu_ID() > 0) { + + sql = "SELECT Name FROM AD_Menu WHERE AD_Menu_ID=?"; + name = DB.getSQLValueString(null, sql, m_Menu.getAD_Menu_ID()); + atts.addAttribute("", "", "ADMenuNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADMenuNameID", "CDATA", ""); + if (m_Menu.getAD_Window_ID() > 0) { + sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; + name = DB.getSQLValueString(null, sql, m_Menu.getAD_Window_ID()); + atts.addAttribute("", "", "ADWindowNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADWindowNameID", "CDATA", ""); + if (m_Menu.getAD_Process_ID() > 0) { + sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; + name = DB.getSQLValueString(null, sql, m_Menu.getAD_Process_ID()); + atts.addAttribute("", "", "ADProcessNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADProcessNameID", "CDATA", ""); + if (m_Menu.getAD_Form_ID() > 0) { + sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?"; + name = DB.getSQLValueString(null, sql, m_Menu.getAD_Form_ID()); + atts.addAttribute("", "", "ADFormNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADFormNameID", "CDATA", ""); + if (m_Menu.getAD_Task_ID() > 0) { + sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?"; + name = DB.getSQLValueString(null, sql, m_Menu.getAD_Task_ID()); + atts.addAttribute("", "", "ADTaskNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADTaskNameID", "CDATA", ""); + if (m_Menu.getAD_Workbench_ID() > 0) { + sql = "SELECT Name FROM AD_Workbench WHERE AD_Workbench_ID=?"; + name = DB.getSQLValueString(null, sql, m_Menu.getAD_Workbench_ID()); + atts.addAttribute("", "", "ADWorkbenchNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADWorkbenchNameID", "CDATA", ""); + if (m_Menu.getAD_Workflow_ID() > 0) { + sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?"; + name = DB.getSQLValueString(null, sql, m_Menu.getAD_Workflow_ID()); + atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", ""); + sql = "SELECT Parent_ID FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?"; + int id = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID()); + if (id > 0) { + sql = "SELECT Name FROM AD_Menu WHERE AD_Menu_ID=?"; + name = DB.getSQLValueString(null, sql, id); + atts.addAttribute("", "", "ADParentMenuNameID", "CDATA", name); + } + sql = "SELECT SeqNo FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?"; + id = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID()); + atts.addAttribute("", "", "ADParentSeqno", "CDATA", "" + id); + atts.addAttribute("", "", "Action", "CDATA", + (m_Menu.getAction() != null ? m_Menu.getAction() : "")); + atts.addAttribute("", "", "Description", "CDATA", (m_Menu + .getDescription() != null ? m_Menu.getDescription() : "")); + atts.addAttribute("", "", "EntityType", "CDATA", (m_Menu + .getEntityType() != null ? m_Menu.getEntityType() : "")); + atts.addAttribute("", "", "isActive", "CDATA", + (m_Menu.isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "isReadOnly", "CDATA", + (m_Menu.isReadOnly() == true ? "true" : "false")); + atts.addAttribute("", "", "isSOTrx", "CDATA", + (m_Menu.isSOTrx() == true ? "true" : "false")); + atts.addAttribute("", "", "isSummary", "CDATA", + (m_Menu.isSummary() == true ? "true" : "false")); + return atts; + } + + private void createApplication(Properties ctx, TransformerHandler document, + int AD_Menu_ID) throws SAXException { + PackOut packOut = (PackOut)ctx.get("PackOutProcess"); + String sql = null; + // int x = 0; + sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, " + + "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID " + + "FROM AD_TreeNoDemm A, AD_Menu B " + + "WHERE A.Node_ID = " + + AD_Menu_ID + " AND A.Node_ID = B.AD_Menu_ID"; + + AttributesImpl atts = new AttributesImpl(); + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + + X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"), + null); + atts = createMenuBinding(atts, m_Menu); + document.startElement("", "", "menu", atts); + if (rs.getInt("AD_WINDOW_ID") > 0 + || rs.getInt("AD_WORKFLOW_ID") > 0 + || rs.getInt("AD_TASK_ID") > 0 + || rs.getInt("AD_PROCESS_ID") > 0 + || rs.getInt("AD_FORM_ID") > 0 + || rs.getInt("AD_WORKBENCH_ID") > 0) { + // Call CreateWindow. + if (rs.getInt("AD_WINDOW_ID") > 0) { + packOut.createWindow(rs.getInt("AD_WINDOW_ID"), atts, document); + } + // Call CreateProcess. + else if (rs.getInt("AD_PROCESS_ID") > 0) { + packOut.createProcess(rs.getInt("AD_PROCESS_ID"), atts, document); + } + // Call CreateTask. + else if (rs.getInt("AD_TASK_ID") > 0) { + packOut.createTask(rs.getInt("AD_TASK_ID"), atts, document); + } + // Call CreateForm. + else if (rs.getInt("AD_FORM_ID") > 0) { + packOut.createForm(rs.getInt("AD_FORM_ID"), atts, document); + } + // Call CreateWorkbench + else if (rs.getInt("AD_WORKBENCH_ID") > 0) { + packOut.createWorkbench(rs.getInt("AD_WORKBENCH_ID"), atts, + document); + } + // Call CreateWorkflow + else if (rs.getInt("AD_Workflow_ID") > 0) { + packOut.createWorkflow(rs.getInt("AD_Workflow_ID"), atts, + document); + } + // Call CreateModule because entry is a summary menu + } else { + createModule(ctx, document, rs.getInt("Node_ID")); + } + document.endElement("", "", "menu"); + } + rs.close(); + pstmt.close(); + pstmt = null; + } catch (Exception e) { + log.log(Level.SEVERE, "getWindows", e); + } finally { + try { + if (pstmt != null) + pstmt.close(); + } catch (Exception e) { + } + pstmt = null; + } + } + + public void createModule(Properties ctx, TransformerHandler document, + int menu_id) throws SAXException { + PackOut packOut = (PackOut)ctx.get("PackOutProcess"); + String sql = null; + sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, " + + "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID " + + "FROM AD_TreeNoDemm A, AD_Menu B " + + "WHERE A.Parent_ID = " + + menu_id + " AND A.Node_ID = B.AD_Menu_ID"; + + AttributesImpl atts = new AttributesImpl(); + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + // Menu tag Start. + X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"), + null); + atts = createMenuBinding(atts, m_Menu); + document.startElement("", "", "menu", atts); + if (rs.getInt("AD_WINDOW_ID") > 0 + || rs.getInt("AD_WORKFLOW_ID") > 0 + || rs.getInt("AD_TASK_ID") > 0 + || rs.getInt("AD_PROCESS_ID") > 0 + || rs.getInt("AD_FORM_ID") > 0 + || rs.getInt("AD_WORKBENCH_ID") > 0) { + // Call CreateWindow. + if (rs.getInt("AD_WINDOW_ID") > 0) { + packOut.createWindow(rs.getInt("AD_WINDOW_ID"), atts, document); + } + // Call CreateProcess. + else if (rs.getInt("AD_PROCESS_ID") > 0) { + packOut.createProcess(rs.getInt("AD_PROCESS_ID"), atts, + document); + } + // Call CreateTask. + else if (rs.getInt("AD_TASK_ID") > 0) { + packOut.createTask(rs.getInt("AD_TASK_ID"), atts, document); + } + // Call CreateForm. + else if (rs.getInt("AD_FORM_ID") > 0) { + packOut.createForm(rs.getInt("AD_FORM_ID"), atts, document); + } + // Call CreateWorkbench + else if (rs.getInt("AD_WORKBENCH_ID") > 0) { + packOut.createWorkbench(rs.getInt("AD_WORKBENCH_ID"), atts, + document); + } + // Call CreateWorkflow + else if (rs.getInt("AD_Workflow_ID") > 0) { + packOut.createWorkflow(rs.getInt("AD_Workflow_ID"), atts, + document); + } + // Call CreateModule because entry is a summary menu + } else { + createModule(ctx, document, rs.getInt("Node_ID")); + } + document.endElement("", "", "menu"); + } + rs.close(); + pstmt.close(); + pstmt = null; + } catch (Exception e) { + log.log(Level.SEVERE, "getWindows", e); + } finally { + try { + if (pstmt != null) + pstmt.close(); + } catch (Exception e) { + } + pstmt = null; + } + } +} diff --git a/base/src/org/adempiere/pipo/handler/MessageElementHandler.java b/base/src/org/adempiere/pipo/handler/MessageElementHandler.java new file mode 100644 index 0000000000..549c15559c --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/MessageElementHandler.java @@ -0,0 +1,128 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.compiere.model.MMessage; +import org.compiere.model.X_AD_Message; +import org.compiere.model.X_AD_Package_Exp_Detail; +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 MessageElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + log.info(elementValue+" "+atts.getValue("Value")); + String entitytype = atts.getValue("EntityType"); + if (entitytype.equals("U") || entitytype.equals("D") && getUpdateMode(ctx).equals("true")) { + String value = atts.getValue("Value"); + int id = get_IDWithColumn(ctx, "AD_Message", "value", value); + + MMessage m_Message = new MMessage(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0){ + AD_Backup_ID = copyRecord(ctx, "AD_Message",m_Message); + Object_Status = "Update"; + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + } + m_Message.setMsgText(atts.getValue("MsgText").replaceAll("'","''").replaceAll(",","")); + m_Message.setMsgTip(atts.getValue("MsgTip").replaceAll("'","''").replaceAll(",","")); + m_Message.setEntityType(atts.getValue("EntityType")); + m_Message.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); + m_Message.setValue(value); + m_Message.setMsgType(atts.getValue("MsgType")); + if (m_Message.save(getTrxName(ctx)) == true){ + record_log (ctx, 1, m_Message.getValue(),"Message", m_Message.get_ID(),AD_Backup_ID, Object_Status,"AD_Message",get_IDWithColumn(ctx, "AD_Message", "value", "AD_Message")); + } + else{ + record_log (ctx, 0, m_Message.getValue(),"Message", m_Message.get_ID(),AD_Backup_ID, Object_Status,"AD_Message",get_IDWithColumn(ctx, "AD_Message", "value", "AD_Message")); + } + } + + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Message_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID); + String sql = "SELECT value FROM AD_Message WHERE AD_Message_ID= " + AD_Message_ID; + AttributesImpl atts = new AttributesImpl(); + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement (sql, getTrxName(ctx)); + + try { + + ResultSet rs = pstmt.executeQuery(); + + while (rs.next()) + { + X_AD_Message m_Message = new X_AD_Message (ctx, AD_Message_ID, null); + createMessageBinding(atts,m_Message); + document.startElement("","","message",atts); + document.endElement("","","message"); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e){ + log.log(Level.SEVERE,"getProcess", e); + } + finally{ + try { + if (pstmt != null) + pstmt.close (); + } + catch (Exception e){} + pstmt = null; + } + } + + private AttributesImpl createMessageBinding( AttributesImpl atts, X_AD_Message m_Message) + { + atts.clear(); + //FIXME: may not need this I guess + //atts.addAttribute("","","AccessLevel","CDATA",(m_Message.getAccessLevel () != null ? m_Message.getAccessLevel ():"")); + atts.addAttribute("","","MsgText","CDATA",(m_Message.getMsgText() != null ? m_Message.getMsgText():"")); + atts.addAttribute("","","MsgType","CDATA",(m_Message.getMsgType() != null ? m_Message.getMsgType ():"")); + atts.addAttribute("","","MsgTip","CDATA",(m_Message.getMsgTip() != null ? m_Message.getMsgTip ():"")); + atts.addAttribute("","","Value","CDATA",(m_Message.getValue() != null ? m_Message.getValue ():"")); + atts.addAttribute("","","EntityType","CDATA",(m_Message.getEntityType () != null ? m_Message.getEntityType ():"")); + atts.addAttribute("","","isActive","CDATA",(m_Message.isActive()== true ? "true":"false")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/OrgRoleElementHandler.java b/base/src/org/adempiere/pipo/handler/OrgRoleElementHandler.java new file mode 100644 index 0000000000..a2ad8a8415 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/OrgRoleElementHandler.java @@ -0,0 +1,130 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.compiere.model.X_AD_Role; +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 OrgRoleElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + log.info(elementValue); + int roleid =0; + int orgid =0; + StringBuffer sqlB = null; + Attributes atts = element.attributes; + if (atts.getValue("rolename")!=null){ + String name = atts.getValue("rolename"); + sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); + roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + if (atts.getValue("orgname")!=null){ + String name = atts.getValue("orgname"); + sqlB = new StringBuffer ("SELECT AD_Org_ID FROM AD_Org WHERE Name= ?"); + orgid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + sqlB = new StringBuffer ("SELECT count(*) FROM AD_Role_OrgAccess WHERE AD_Role_ID=? and AD_Org_ID=?"); + int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,orgid); + int AD_Backup_ID = -1; + String Object_Status = null; + if (count>0){ + Object_Status = "Update"; + sqlB = new StringBuffer ("UPDATE AD_Role_OrgAccess ") + .append( "SET isActive = '" + atts.getValue("isActive") ) + .append( "', isReadOnly = '" + atts.getValue("isReadOnly") ) + .append( "' WHERE AD_Role_ID = " + roleid ) + .append( " and AD_Org_ID = " + orgid ); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) + log.info("Update to org access failed"); + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + sqlB = new StringBuffer ("Insert INTO AD_Role_OrgAccess") + .append( "(AD_Client_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_Role_ID, AD_Org_ID, isActive, isReadOnly) " ) + .append( "VALUES(" ) + .append( " "+ Env.getAD_Client_ID(ctx) ) + .append( ", "+ Env.getAD_User_ID(ctx) ) + .append( ", "+ Env.getAD_User_ID(ctx) ) + .append( ", " + roleid ) + .append( ", " + orgid ) + .append( ", '" + atts.getValue("isActive") ) + .append( "', '" + atts.getValue("isReadOnly")+"')"); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) + log.info("Insert to org access failed"); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Org_ID = Env.getContextAsInt(ctx, "AD_Org_ID"); + int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + AttributesImpl atts = new AttributesImpl(); + createOrgAccessBinding(atts, AD_Org_ID, AD_Role_ID); + document.startElement("", "", "OrgAccess", atts); + document.endElement("", "", "OrgAccess"); + + } + + private AttributesImpl createOrgAccessBinding(AttributesImpl atts, + int org_id, int role_id) { + String sql = null; + String name = null; + atts.clear(); + + sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?"; + name = DB.getSQLValueString(null, sql, org_id); + atts.addAttribute("", "", "orgname", "CDATA", name); + + sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; + name = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "rolename", "CDATA", name); + + sql = "SELECT isActive FROM AD_Role_OrgAccess WHERE AD_Org_ID=" + + org_id + " and AD_Role_ID=?"; + String TrueFalse = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isActive", "CDATA", TrueFalse); + + sql = "SELECT isReadOnly FROM AD_Role_OrgAccess WHERE AD_Org_ID=" + + org_id + " and AD_Role_ID=?"; + String isReadOnly = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isReadOnly", "CDATA", isReadOnly); + + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/PreferenceElementHandler.java b/base/src/org/adempiere/pipo/handler/PreferenceElementHandler.java new file mode 100644 index 0000000000..a70e87a35c --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/PreferenceElementHandler.java @@ -0,0 +1,113 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.MPreference; +import org.compiere.model.X_AD_Preference; +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 PreferenceElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + log.info(elementValue); + + // TODO Add User_ID + Attributes atts = element.attributes; + int windowid = get_ID(ctx, "AD_Window", atts.getValue("ADWindowNameID")); + if (windowid <= 0) { + element.defer = true; + return; + } + + StringBuffer sqlB = new StringBuffer( + "select AD_Preference_ID from AD_Preference where ").append( + " Attribute = '" + atts.getValue("Attribute") + "'").append( + " and AD_Window_ID = ?"); + int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), windowid); + MPreference m_Preference = new MPreference(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Preference", m_Preference); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + sqlB = null; + m_Preference.setAD_Window_ID(windowid); + m_Preference.setAttribute(atts.getValue("Attribute")); + m_Preference.setValue(atts.getValue("Value")); + if (m_Preference.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Preference.getAttribute(), "Preference", + m_Preference.get_ID(), AD_Backup_ID, Object_Status, + "AD_Preference", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Preference")); + } else { + record_log(ctx, 0, m_Preference.getAttribute(), "Preference", + m_Preference.get_ID(), AD_Backup_ID, Object_Status, + "AD_Preference", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Preference")); + throw new POSaveFailedException("Preference"); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Preference_ID = Env.getContextAsInt(ctx, + X_AD_Preference.COLUMNNAME_AD_Preference_ID); + X_AD_Preference m_Preference = new X_AD_Preference(ctx, + AD_Preference_ID, getTrxName(ctx)); + AttributesImpl atts = new AttributesImpl(); + createPreferenceBinding(atts, m_Preference); + document.startElement("", "", "preference", atts); + document.endElement("", "", "preference"); + } + + private AttributesImpl createPreferenceBinding(AttributesImpl atts, + X_AD_Preference m_Preference) { + String sql = null; + String name = null; + atts.clear(); + sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; + name = DB.getSQLValueString(null, sql, m_Preference.getAD_Window_ID()); + atts.addAttribute("", "", "ADWindowNameID", "CDATA", name); + sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?"; + name = DB.getSQLValueString(null, sql, m_Preference.getAD_User_ID()); + atts.addAttribute("", "", "ADUserNameID", "CDATA", name); + atts.addAttribute("", "", "Attribute", "CDATA", m_Preference + .getAttribute()); + atts.addAttribute("", "", "Value", "CDATA", m_Preference.getValue()); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/PrintFormatElementHandler.java b/base/src/org/adempiere/pipo/handler/PrintFormatElementHandler.java new file mode 100644 index 0000000000..af98ca7436 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/PrintFormatElementHandler.java @@ -0,0 +1,337 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.MTable; +import org.compiere.model.X_AD_Package_Exp_Detail; +import org.compiere.model.X_AD_PrintFormat; +import org.compiere.model.X_AD_PrintFormatItem; +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 PrintFormatElementHandler extends AbstractElementHandler { + + private PrintFormatItemElementHandler itemHandler = new PrintFormatItemElementHandler(); + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("Name")); + + String name = atts.getValue("Name"); + int id = get_IDWithColumn(ctx, "AD_PrintFormat", "Name", name); + X_AD_PrintFormat m_PrintFormat = new X_AD_PrintFormat(ctx, id, + getTrxName(ctx)); + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_PrintFormat", m_PrintFormat); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + + name = atts.getValue("ADReportviewnameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_ReportView", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_PrintFormat.setAD_ReportView_ID(id); + } + + name = atts.getValue("ADTableNameID"); + id = get_IDWithColumn(ctx, "AD_Table", "TableName", name); + if (id == 0) { + MTable m_Table = new MTable(ctx, 0, getTrxName(ctx)); + m_Table.setAccessLevel("3"); + m_Table.setName(name); + m_Table.setTableName(name); + if (m_Table.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Table.getName(), "Table", + m_Table.get_ID(), 0, "New", "AD_Table", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Table")); + } else { + record_log(ctx, 0, m_Table.getName(), "Table", + m_Table.get_ID(), 0, "New", "AD_Table", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Table")); + } + id = get_IDWithColumn(ctx, "AD_Table", "TableName", name); + } + m_PrintFormat.setAD_Table_ID(id); + + name = atts.getValue("ADPrintTableFormatID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_PrintTableFormat", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_PrintFormat.setAD_PrintTableFormat_ID(id); + } + + name = atts.getValue("ADPrintColorID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_PrintColor", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_PrintFormat.setAD_PrintColor_ID(id); + } + + name = atts.getValue("ADPrintFontID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_PrintFont", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_PrintFormat.setAD_PrintFont_ID(id); + } + + name = atts.getValue("ADPrintPaperID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_PrintPaper", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_PrintFormat.setAD_PrintPaper_ID(id); + } + + m_PrintFormat.setDescription(atts.getValue("Description").replaceAll( + "'", "''").replaceAll(",", "")); + m_PrintFormat.setName(atts.getValue("Name")); + m_PrintFormat.setPrinterName(atts.getValue("PrinterName")); + m_PrintFormat.setFooterMargin(Integer.parseInt(atts + .getValue("FooterMargin"))); + + m_PrintFormat.setHeaderMargin(Integer.parseInt(atts + .getValue("HeaderMargin"))); + m_PrintFormat.setCreateCopy(atts.getValue("CreateCopy")); + m_PrintFormat.setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() : true); + + m_PrintFormat.setIsTableBased(Boolean.valueOf( + atts.getValue("isTableBased")).booleanValue()); + m_PrintFormat.setIsForm(Boolean.valueOf(atts.getValue("isForm")) + .booleanValue()); + m_PrintFormat.setIsStandardHeaderFooter(Boolean.valueOf( + atts.getValue("isStandardHeader")).booleanValue()); + + m_PrintFormat.setIsDefault(Boolean.valueOf(atts.getValue("isDefault")) + .booleanValue()); + if (m_PrintFormat.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_PrintFormat.getName(), "PrintFormat", + m_PrintFormat.get_ID(), AD_Backup_ID, Object_Status, + "AD_PrintFormat", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_PrintFormat")); + } else { + record_log(ctx, 0, m_PrintFormat.getName(), "PrintFormat", + m_PrintFormat.get_ID(), AD_Backup_ID, Object_Status, + "AD_PrintFormat", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_PrintFormat")); + throw new POSaveFailedException("PrintFormat"); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_PrintFormat_ID = Env.getContextAsInt(ctx, + X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID); + AttributesImpl atts = new AttributesImpl(); + String sql = null; + sql = "SELECT AD_PrintFormat_ID " + + "FROM AD_PrintFormat " + + "WHERE AD_PrintFormat_ID in " + + "(( select AD_PrintFormatChild_ID from AD_PrintFormatItem WHERE AD_PrintFormat_ID = " + + AD_PrintFormat_ID + " AND PrintFormatType = 'P'), " + + AD_PrintFormat_ID + ")"; + + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + + X_AD_PrintFormat m_Printformat = new X_AD_PrintFormat(ctx, rs + .getInt("AD_PrintFormat_ID"), null); + createPrintFormatBinding(atts, m_Printformat); + document.startElement("", "", "printformat", atts); + + String sql2 = "SELECT * FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID= " + + AD_PrintFormat_ID; + PreparedStatement pstmt2 = null; + pstmt2 = DB.prepareStatement(sql2, getTrxName(ctx)); + try { + ResultSet rs2 = pstmt2.executeQuery(); + while (rs2.next()) { + createItem(ctx, document, rs2 + .getInt("AD_PrintFormatItem_ID")); + } + rs2.close(); + pstmt2.close(); + pstmt2 = null; + } finally { + try { + if (pstmt2 != null) + pstmt2.close(); + } catch (Exception e) { + } + pstmt2 = null; + } + document.endElement("", "", "printformat"); + } + rs.close(); + pstmt.close(); + pstmt = null; + } catch (Exception e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + if (e instanceof SAXException) + throw (SAXException) e; + else if (e instanceof SQLException) + throw new DatabaseAccessException("Window", e); + else if (e instanceof RuntimeException) + throw (RuntimeException) e; + else + throw new RuntimeException("Window", e); + } finally { + try { + if (pstmt != null) + pstmt.close(); + } catch (Exception e) { + } + pstmt = null; + } + + } + + private void createItem(Properties ctx, TransformerHandler document, + int AD_PrintFormatItem_ID) throws SAXException { + Env.setContext(ctx, + X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID, + AD_PrintFormatItem_ID); + itemHandler.create(ctx, document); + ctx.remove(X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID); + } + + private AttributesImpl createPrintFormatBinding(AttributesImpl atts, + X_AD_PrintFormat m_Printformat) { + String sql = null; + String name = null; + atts.clear(); + if (m_Printformat.getAD_ReportView_ID() > 0) { + sql = "SELECT Name FROM AD_ReportView WHERE AD_ReportView_ID=?"; + name = DB.getSQLValueString(null, sql, m_Printformat + .getAD_ReportView_ID()); + atts.addAttribute("", "", "ADReportviewnameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADReportviewnameID", "CDATA", ""); + + if (m_Printformat.getAD_Table_ID() > 0) { + sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; + name = DB.getSQLValueString(null, sql, m_Printformat + .getAD_Table_ID()); + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADTableNameID", "CDATA", ""); + + if (m_Printformat.getAD_PrintTableFormat_ID() > 0) { + sql = "SELECT Name FROM AD_PrintTableFormat WHERE AD_PrintTableFormat_ID=?"; + name = DB.getSQLValueString(null, sql, m_Printformat + .getAD_PrintTableFormat_ID()); + atts.addAttribute("", "", "ADPrintTableFormatID", "CDATA", name); + } else + atts.addAttribute("", "", "ADPrintTableFormatID", "CDATA", ""); + + if (m_Printformat.getAD_PrintColor_ID() > 0) { + sql = "SELECT Name FROM AD_PrintColor WHERE AD_PrintColor_ID=?"; + name = DB.getSQLValueString(null, sql, m_Printformat + .getAD_PrintColor_ID()); + atts.addAttribute("", "", "ADPrintColorID", "CDATA", name); + } else + atts.addAttribute("", "", "ADPrintColorID", "CDATA", ""); + + if (m_Printformat.getAD_PrintFont_ID() > 0) { + sql = "SELECT Name FROM AD_PrintFont WHERE AD_PrintFont_ID=?"; + name = DB.getSQLValueString(null, sql, m_Printformat + .getAD_PrintFont_ID()); + atts.addAttribute("", "", "ADPrintFontID", "CDATA", name); + } else + atts.addAttribute("", "", "ADPrintFontID", "CDATA", ""); + + if (m_Printformat.getAD_PrintPaper_ID() > 0) { + sql = "SELECT Name FROM AD_PrintPaper WHERE AD_PrintPaper_ID=?"; + name = DB.getSQLValueString(null, sql, m_Printformat + .getAD_PrintPaper_ID()); + atts.addAttribute("", "", "ADPrintPaperID", "CDATA", name); + } else + atts.addAttribute("", "", "ADPrintPaperID", "CDATA", ""); + + atts.addAttribute("", "", "Description", "CDATA", + (m_Printformat.getDescription() != null ? m_Printformat + .getDescription() : "")); + atts + .addAttribute("", "", "Name", "CDATA", + (m_Printformat.getName() != null ? m_Printformat + .getName() : "")); + atts.addAttribute("", "", "PrinterName", "CDATA", + (m_Printformat.getPrinterName() != null ? m_Printformat + .getPrinterName() : "")); + atts.addAttribute("", "", "FooterMargin", "CDATA", "" + + m_Printformat.getFooterMargin()); + atts.addAttribute("", "", "HeaderMargin", "CDATA", "" + + m_Printformat.getHeaderMargin()); + atts.addAttribute("", "", "CreateCopy", "CDATA", (m_Printformat + .getCreateCopy() != null ? m_Printformat.getCreateCopy() : "")); + atts.addAttribute("", "", "isActive", "CDATA", (m_Printformat + .isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "isTableBased", "CDATA", (m_Printformat + .isTableBased() == true ? "true" : "false")); + atts.addAttribute("", "", "isForm", "CDATA", + (m_Printformat.isForm() == true ? "true" : "false")); + atts.addAttribute("", "", "isStandardHeader", "CDATA", (m_Printformat + .isStandardHeaderFooter() == true ? "true" : "false")); + atts.addAttribute("", "", "isDefault", "CDATA", (m_Printformat + .isDefault() == true ? "true" : "false")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/PrintFormatItemElementHandler.java b/base/src/org/adempiere/pipo/handler/PrintFormatItemElementHandler.java new file mode 100644 index 0000000000..7a70ec2441 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/PrintFormatItemElementHandler.java @@ -0,0 +1,408 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.X_AD_PrintFormatItem; +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 PrintFormatItemElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("Name")); + + String name = atts.getValue("Name"); + int id = get_IDWithMaster(ctx, "AD_PrintFormatItem", name, + "AD_PrintFormat", atts.getValue("ADPrintFormatNameID")); + + X_AD_PrintFormatItem m_PrintFormatItem = new X_AD_PrintFormatItem(ctx, + id, getTrxName(ctx)); + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_PrintFormatItem", + m_PrintFormatItem); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + m_PrintFormatItem.setName(name); + name = atts.getValue("ADPrintFormatNameID"); + id = get_IDWithColumn(ctx, "AD_PrintFormat", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_PrintFormatItem.setAD_PrintFormat_ID(id); + // name = atts.getValue("ADPrintFormatChildNameID"); + // id = get_IDWithColumn("AD_PrintFormat", "Name", name); + // m_PrintFormatItem.setAD_PrintFormatChild_ID(id); + name = atts.getValue("ADTableNameID"); + int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", name); + name = atts.getValue("ADColumnNameID"); + id = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", name, + "AD_Table", tableid); + if (id > 0) + m_PrintFormatItem.setAD_Column_ID(id); + + name = atts.getValue("ADPrintGraphID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_PrintGraph", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_PrintFormatItem.setAD_PrintGraph_ID(id); + } + + name = atts.getValue("ADPrintColorID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_PrintColor", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_PrintFormatItem.setAD_PrintColor_ID(id); + } + + name = atts.getValue("ADPrintFontID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_PrintFont", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_PrintFormatItem.setAD_PrintFont_ID(id); + } + + m_PrintFormatItem.setPrintName(atts.getValue("PrintName")); + m_PrintFormatItem.setName(atts.getValue("Name")); + m_PrintFormatItem.setPrintAreaType(atts.getValue("PrintAreaType")); + + m_PrintFormatItem.setSeqNo(Integer.parseInt(atts.getValue("SeqNo"))); + m_PrintFormatItem.setPrintFormatType(atts.getValue("PrintFormatType")); + m_PrintFormatItem.setXSpace(Integer.parseInt(atts.getValue("XSpace"))); + + m_PrintFormatItem.setYSpace(Integer.parseInt(atts.getValue("YSpace"))); + m_PrintFormatItem.setXPosition(Integer.parseInt(atts + .getValue("Xposition"))); + m_PrintFormatItem.setYPosition(Integer.parseInt(atts + .getValue("Yposition"))); + + m_PrintFormatItem.setMaxWidth(Integer.parseInt(atts + .getValue("MaxWidth"))); + m_PrintFormatItem.setMaxHeight(Integer.parseInt(atts + .getValue("MaxHieght"))); + m_PrintFormatItem.setSortNo(Integer.parseInt(atts.getValue("SortNo"))); + + m_PrintFormatItem.setFieldAlignmentType(atts + .getValue("FieldAlignmentType")); + m_PrintFormatItem.setLineAlignmentType(atts + .getValue("LineAlignmentType")); + m_PrintFormatItem.setImageURL(atts.getValue("ImageURL")); + m_PrintFormatItem.setArcDiameter(Integer.parseInt(atts + .getValue("ArcDiameter"))); + m_PrintFormatItem.setLineWidth(Integer.parseInt(atts + .getValue("LineWidth"))); + m_PrintFormatItem.setShapeType(atts.getValue("ShapeType")); + + m_PrintFormatItem.setBelowColumn(Integer.parseInt(atts + .getValue("BelowColumn"))); + m_PrintFormatItem.setPrintNameSuffix(atts.getValue("PrintNameSuffix")); + m_PrintFormatItem.setRunningTotalLines(Integer.parseInt(atts + .getValue("RunningTotalLines"))); + + m_PrintFormatItem + .setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() + : true); + m_PrintFormatItem.setIsPrinted(Boolean.valueOf( + atts.getValue("isPrinted")).booleanValue()); + m_PrintFormatItem.setIsRelativePosition(Boolean.valueOf( + atts.getValue("isRelativePosition")).booleanValue()); + m_PrintFormatItem.setIsNextLine(Boolean.valueOf( + atts.getValue("isNextLine")).booleanValue()); + + m_PrintFormatItem.setIsHeightOneLine(Boolean.valueOf( + atts.getValue("isHeightOneLine")).booleanValue()); + m_PrintFormatItem.setIsOrderBy(Boolean.valueOf( + atts.getValue("isOrderBy")).booleanValue()); + m_PrintFormatItem.setIsGroupBy(Boolean.valueOf( + atts.getValue("isGroupBy")).booleanValue()); + + m_PrintFormatItem.setIsPageBreak(Boolean.valueOf( + atts.getValue("isPageBreak")).booleanValue()); + m_PrintFormatItem.setIsSummarized(Boolean.valueOf( + atts.getValue("isSummarized")).booleanValue()); + m_PrintFormatItem.setImageIsAttached(Boolean.valueOf( + atts.getValue("isImageIsAttached")).booleanValue()); + + m_PrintFormatItem.setIsAveraged(Boolean.valueOf( + atts.getValue("isAveraged")).booleanValue()); + m_PrintFormatItem.setIsCounted(Boolean.valueOf( + atts.getValue("isCounted")).booleanValue()); + m_PrintFormatItem.setIsSetNLPosition(Boolean.valueOf( + atts.getValue("isSetNLPosition")).booleanValue()); + m_PrintFormatItem.setIsSuppressNull(Boolean.valueOf( + atts.getValue("isSuppressNull")).booleanValue()); + + m_PrintFormatItem.setIsFixedWidth(Boolean.valueOf( + atts.getValue("isFixedWidth")).booleanValue()); + m_PrintFormatItem.setIsNextPage(Boolean.valueOf( + atts.getValue("isNextPage")).booleanValue()); + m_PrintFormatItem.setIsMaxCalc(Boolean.valueOf( + atts.getValue("isMaxCalc")).booleanValue()); + m_PrintFormatItem.setIsMinCalc(Boolean.valueOf( + atts.getValue("isMinCalc")).booleanValue()); + + m_PrintFormatItem.setIsRunningTotal(Boolean.valueOf( + atts.getValue("isRunningTotal")).booleanValue()); + m_PrintFormatItem.setIsVarianceCalc(Boolean.valueOf( + atts.getValue("isVarianceCalc")).booleanValue()); + m_PrintFormatItem.setIsDeviationCalc(Boolean.valueOf( + atts.getValue("isDeviationCalc")).booleanValue()); + + if (m_PrintFormatItem.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_PrintFormatItem.getName(), "PrintFormatItem", + m_PrintFormatItem.get_ID(), AD_Backup_ID, Object_Status, + "AD_PrintFormatItem", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_PrintFormatItem")); + } else { + record_log(ctx, 0, m_PrintFormatItem.getName(), "PrintFormatItem", + m_PrintFormatItem.get_ID(), AD_Backup_ID, Object_Status, + "AD_PrintFormatItem", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_PrintFormatItem")); + throw new POSaveFailedException("PrintFormatItem"); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_PrintFormatItem_ID = Env.getContextAsInt(ctx, + X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID); + X_AD_PrintFormatItem m_PrintFormatItem = new X_AD_PrintFormatItem(ctx, + AD_PrintFormatItem_ID, null); + AttributesImpl atts = new AttributesImpl(); + createPrintFormatItemBinding(atts, m_PrintFormatItem); + document.startElement("", "", "printformatitem", atts); + document.endElement("", "", "printformatitem"); + } + + private AttributesImpl createPrintFormatItemBinding(AttributesImpl atts, + X_AD_PrintFormatItem m_PrintformatItem) { + String sql = null; + String name = null; + atts.clear(); + if (m_PrintformatItem.getAD_PrintFormat_ID() > 0) { + sql = "SELECT Name FROM AD_PrintFormat WHERE AD_PrintFormat_ID=?"; + name = DB.getSQLValueString(null, sql, m_PrintformatItem + .getAD_PrintFormat_ID()); + atts.addAttribute("", "", "ADPrintFormatNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADPrintFormatNameID", "CDATA", ""); + + if (m_PrintformatItem.getAD_PrintFormatChild_ID() > 0) { + sql = "SELECT Name FROM AD_PrintFormat WHERE AD_PrintFormat_ID=?"; + name = DB.getSQLValueString(null, sql, m_PrintformatItem + .getAD_PrintFormatChild_ID()); + atts + .addAttribute("", "", "ADPrintFormatChildNameID", "CDATA", + name); + } else + atts.addAttribute("", "", "ADPrintFormatChildNameID", "CDATA", ""); + + if (m_PrintformatItem.getAD_Column_ID() > 0) { + sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null, sql, m_PrintformatItem + .getAD_Column_ID()); + atts.addAttribute("", "", "ADColumnNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADColumnNameID", "CDATA", ""); + + if (m_PrintformatItem.getAD_Column_ID() > 0) { + sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?"; + int tableID = DB.getSQLValue(null, sql, m_PrintformatItem + .getAD_Column_ID()); + sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; + name = DB.getSQLValueString(null, sql, tableID); + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADTableNameID", "CDATA", ""); + + if (m_PrintformatItem.getAD_PrintGraph_ID() > 0) { + sql = "SELECT Name FROM AD_PrintGraph WHERE AD_PrintGraph_ID=?"; + name = DB.getSQLValueString(null, sql, m_PrintformatItem + .getAD_PrintGraph_ID()); + atts.addAttribute("", "", "ADPrintGraphID", "CDATA", name); + } else + atts.addAttribute("", "", "ADPrintGraphID", "CDATA", ""); + + if (m_PrintformatItem.getAD_PrintColor_ID() > 0) { + sql = "SELECT Name FROM AD_PrintColor WHERE AD_PrintColor_ID=?"; + name = DB.getSQLValueString(null, sql, m_PrintformatItem + .getAD_PrintColor_ID()); + atts.addAttribute("", "", "ADPrintColorID", "CDATA", name); + } else + atts.addAttribute("", "", "ADPrintColorID", "CDATA", ""); + + if (m_PrintformatItem.getAD_PrintFont_ID() > 0) { + sql = "SELECT Name FROM AD_PrintFont WHERE AD_PrintFont_ID=?"; + name = DB.getSQLValueString(null, sql, m_PrintformatItem + .getAD_PrintFont_ID()); + atts.addAttribute("", "", "ADPrintFontID", "CDATA", name); + } else + atts.addAttribute("", "", "ADPrintFontID", "CDATA", ""); + + atts.addAttribute("", "", "PrintName", "CDATA", + (m_PrintformatItem.getPrintName() != null ? m_PrintformatItem + .getPrintName() : "")); + atts.addAttribute("", "", "Name", "CDATA", + (m_PrintformatItem.getName() != null ? m_PrintformatItem + .getName() : "")); + atts.addAttribute("", "", "PrintAreaType", "CDATA", (m_PrintformatItem + .getPrintAreaType() != null ? m_PrintformatItem + .getPrintAreaType() : "")); + atts.addAttribute("", "", "SeqNo", "CDATA", "" + + m_PrintformatItem.getSeqNo()); + atts.addAttribute("", "", "PrintFormatType", "CDATA", m_PrintformatItem + .getPrintFormatType()); + atts.addAttribute("", "", "XSpace", "CDATA", ("" + m_PrintformatItem + .getXSpace())); + atts.addAttribute("", "", "YSpace", "CDATA", ("" + m_PrintformatItem + .getYSpace())); + atts.addAttribute("", "", "Xposition", "CDATA", ("" + m_PrintformatItem + .getXPosition())); + atts.addAttribute("", "", "Yposition", "CDATA", ("" + m_PrintformatItem + .getYPosition())); + atts.addAttribute("", "", "MaxWidth", "CDATA", ("" + m_PrintformatItem + .getMaxWidth())); + atts.addAttribute("", "", "MaxHieght", "CDATA", ("" + m_PrintformatItem + .getMaxHeight())); + atts.addAttribute("", "", "SortNo", "CDATA", ("" + m_PrintformatItem + .getSortNo())); + atts + .addAttribute( + "", + "", + "FieldAlignmentType", + "CDATA", + (m_PrintformatItem.getFieldAlignmentType() != null ? m_PrintformatItem + .getFieldAlignmentType() + : "")); + atts + .addAttribute( + "", + "", + "LineAlignmentType", + "CDATA", + (m_PrintformatItem.getLineAlignmentType() != null ? m_PrintformatItem + .getLineAlignmentType() + : "")); + atts.addAttribute("", "", "ImageURL", "CDATA", (m_PrintformatItem + .getImageURL() != null ? m_PrintformatItem.getImageURL() : "")); + atts.addAttribute("", "", "BelowColumn", "CDATA", + ("" + m_PrintformatItem.getBelowColumn())); + atts.addAttribute("", "", "RunningTotalLines", "CDATA", + ("" + m_PrintformatItem.getRunningTotalLines())); + atts + .addAttribute( + "", + "", + "PrintNameSuffix", + "CDATA", + (m_PrintformatItem.getPrintNameSuffix() != null ? m_PrintformatItem + .getPrintNameSuffix() + : "")); + atts.addAttribute("", "", "ArcDiameter", "CDATA", "" + + m_PrintformatItem.getArcDiameter()); + atts.addAttribute("", "", "LineWidth", "CDATA", "" + + m_PrintformatItem.getLineWidth()); + atts + .addAttribute("", "", "ShapeType", "CDATA", m_PrintformatItem + .getShapeType() != null ? m_PrintformatItem + .getShapeType() : ""); + atts.addAttribute("", "", "isActive", "CDATA", (m_PrintformatItem + .isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "isPrinted", "CDATA", (m_PrintformatItem + .isPrinted() == true ? "true" : "false")); + atts.addAttribute("", "", "isRelativePosition", "CDATA", + (m_PrintformatItem.isRelativePosition() == true ? "true" + : "false")); + atts.addAttribute("", "", "isNextLine", "CDATA", (m_PrintformatItem + .isNextLine() == true ? "true" : "false")); + atts + .addAttribute("", "", "isHeightOneLine", "CDATA", + (m_PrintformatItem.isHeightOneLine() == true ? "true" + : "false")); + atts.addAttribute("", "", "isOrderBy", "CDATA", (m_PrintformatItem + .isOrderBy() == true ? "true" : "false")); + atts.addAttribute("", "", "isGroupBy", "CDATA", (m_PrintformatItem + .isGroupBy() == true ? "true" : "false")); + atts.addAttribute("", "", "isPageBreak", "CDATA", (m_PrintformatItem + .isPageBreak() == true ? "true" : "false")); + atts.addAttribute("", "", "isSummarized", "CDATA", (m_PrintformatItem + .isSummarized() == true ? "true" : "false")); + atts.addAttribute("", "", "isImageIsAttached", "CDATA", + (m_PrintformatItem.isImageIsAttached() == true ? "true" + : "false")); + atts.addAttribute("", "", "isAveraged", "CDATA", (m_PrintformatItem + .isAveraged() == true ? "true" : "false")); + atts.addAttribute("", "", "isCounted", "CDATA", (m_PrintformatItem + .isCounted() == true ? "true" : "false")); + atts + .addAttribute("", "", "isSetNLPosition", "CDATA", + (m_PrintformatItem.isSetNLPosition() == true ? "true" + : "false")); + atts.addAttribute("", "", "isSuppressNull", "CDATA", (m_PrintformatItem + .isSuppressNull() == true ? "true" : "false")); + atts.addAttribute("", "", "isFixedWidth", "CDATA", (m_PrintformatItem + .isFixedWidth() == true ? "true" : "false")); + atts.addAttribute("", "", "isNextPage", "CDATA", (m_PrintformatItem + .isNextPage() == true ? "true" : "false")); + atts.addAttribute("", "", "isMaxCalc", "CDATA", (m_PrintformatItem + .isMaxCalc() == true ? "true" : "false")); + atts.addAttribute("", "", "isMinCalc", "CDATA", (m_PrintformatItem + .isMinCalc() == true ? "true" : "false")); + atts.addAttribute("", "", "isRunningTotal", "CDATA", (m_PrintformatItem + .isRunningTotal() == true ? "true" : "false")); + atts.addAttribute("", "", "isVarianceCalc", "CDATA", (m_PrintformatItem + .isVarianceCalc() == true ? "true" : "false")); + atts + .addAttribute("", "", "isDeviationCalc", "CDATA", + (m_PrintformatItem.isDeviationCalc() == true ? "true" + : "false")); + + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/ProcessAccessElementHandler.java b/base/src/org/adempiere/pipo/handler/ProcessAccessElementHandler.java new file mode 100644 index 0000000000..f771044171 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/ProcessAccessElementHandler.java @@ -0,0 +1,138 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.compiere.model.X_AD_Process; +import org.compiere.model.X_AD_Role; +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 ProcessAccessElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + log.info(elementValue); + int roleid =0; + int processid =0; + StringBuffer sqlB = null; + Attributes atts = element.attributes; + if (atts.getValue("rolename")!=null){ + String name = atts.getValue("rolename"); + sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); + roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + if (atts.getValue("processname")!=null){ + String name = atts.getValue("processname"); + sqlB = new StringBuffer ("SELECT AD_Process_ID FROM AD_Process WHERE Name= ?"); + processid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + sqlB = new StringBuffer ("SELECT count(*) FROM AD_Process_Access WHERE AD_Role_ID=? and AD_Process_ID=?"); + int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,processid); + int AD_Backup_ID = -1; + String Object_Status = null; + + if (count>0){ + Object_Status = "Update"; + sqlB = new StringBuffer ("UPDATE AD_Process_Access ") + .append( "SET isActive = '" + atts.getValue("isActive") ) + .append( "', isReadWrite = '" + atts.getValue("isReadWrite") ) + .append( "' WHERE AD_Role_ID = " + roleid ) + .append( " and AD_Process_ID = " + processid ); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) { + log.info("Update to process access failed"); + throw new DatabaseAccessException("Update to process access failed"); + } + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + sqlB = new StringBuffer ("Insert INTO AD_Process_Access") + .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_Role_ID, AD_Process_ID, isActive, isReadWrite) " ) + .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( ", " + roleid ) + .append( ", " + processid ) + .append( ", '" + atts.getValue("isActive") ) + .append( "', '" + atts.getValue("isReadWrite")+"')" ); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) { + log.info("Insert to process access failed"); + throw new DatabaseAccessException("Insert to process access failed"); + } + } + + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Process_ID = Env.getContextAsInt(ctx, X_AD_Process.COLUMNNAME_AD_Process_ID); + int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + AttributesImpl atts = new AttributesImpl(); + createProcessAccessBinding(atts, AD_Process_ID, AD_Role_ID); + document.startElement("", "", "processaccess", atts); + document.endElement("", "", "processaccess"); + } + + private AttributesImpl createProcessAccessBinding(AttributesImpl atts, + int process_id, int role_id) { + String sql = null; + String name = null; + atts.clear(); + + sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; + name = DB.getSQLValueString(null, sql, process_id); + atts.addAttribute("", "", "processname", "CDATA", name); + + sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; + name = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "rolename", "CDATA", name); + + sql = "SELECT isActive FROM AD_Process_Access WHERE AD_Process_ID=" + + process_id + " and AD_Role_ID=?"; + String TrueFalse = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isActive", "CDATA", TrueFalse); + + sql = "SELECT isReadWrite FROM AD_Process_Access WHERE AD_Process_ID=" + + process_id + " and AD_Role_ID=?"; + String isReadWrite = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isReadWrite", "CDATA", isReadWrite); + + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/ProcessElementHandler.java b/base/src/org/adempiere/pipo/handler/ProcessElementHandler.java new file mode 100644 index 0000000000..d3139b1424 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/ProcessElementHandler.java @@ -0,0 +1,317 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.PackOut; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.MProcess; +import org.compiere.model.MSequence; +import org.compiere.model.X_AD_Process; +import org.compiere.model.X_AD_Process_Para; +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 ProcessElementHandler extends AbstractElementHandler { + + private ProcessParaElementHandler paraHandler = new ProcessParaElementHandler(); + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("Name")); + int id = 0; + String entitytype = atts.getValue("EntityType"); + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 + && getUpdateMode(ctx).compareTo("true") == 0) { + String name = atts.getValue("Name"); + + // Get New process. + id = get_ID(ctx, "AD_Process", name); + + MProcess m_Process = null; + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0) { + m_Process = new MProcess(ctx, id, getTrxName(ctx)); + AD_Backup_ID = copyRecord(ctx, "AD_Process", m_Process); + Object_Status = "Update"; + } else { + m_Process = new MProcess(ctx, id, getTrxName(ctx)); + id = MSequence.getNextID(Env.getAD_Client_ID(ctx), + "AD_Process", getTrxName(ctx)); + m_Process.setAD_Process_ID(id); + Object_Status = "New"; + AD_Backup_ID = 0; + } + m_Process.setName(name); + + name = atts.getValue("ADWorkflowNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Workflow", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Process.setAD_Workflow_ID(id); + } + + name = atts.getValue("ADPrintFormatNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_PrintFormat", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Process.setAD_PrintFormat_ID(id); + } + + name = atts.getValue("ADReportViewNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_ReportView", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Process.setAD_ReportView_ID(id); + } + + m_Process.setAccessLevel(atts.getValue("AccessLevel")); + m_Process.setClassname(atts.getValue("Classname")); + m_Process.setDescription(atts.getValue("Description").replaceAll( + "'", "''").replaceAll(",", "")); + m_Process.setEntityType(atts.getValue("EntityType")); + m_Process.setHelp(atts.getValue("Help").replaceAll("'", "''") + .replaceAll(",", "")); + m_Process.setIsBetaFunctionality(Boolean.valueOf( + atts.getValue("isBetaFunctionality")).booleanValue()); + m_Process.setIsDirectPrint(Boolean.valueOf( + atts.getValue("isDirectPrint")).booleanValue()); + m_Process.setIsReport(Boolean.valueOf(atts.getValue("isReport")) + .booleanValue()); + m_Process.setName(atts.getValue("Name")); + + m_Process.setProcedureName(atts.getValue("ProcedureName")); + m_Process.setStatistic_Count(0); + m_Process.setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() : true); + m_Process.setStatistic_Seconds(0); + m_Process.setValue(atts.getValue("Value")); + m_Process.setWorkflowValue(atts.getValue("WorkflowValue")); + if (m_Process.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Process.getName(), "Process", m_Process + .get_ID(), AD_Backup_ID, Object_Status, "AD_Process", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Process")); + } else { + record_log(ctx, 0, m_Process.getName(), "Process", m_Process + .get_ID(), AD_Backup_ID, Object_Status, "AD_Process", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Process")); + throw new POSaveFailedException("Process"); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Process_ID = Env.getContextAsInt(ctx, "AD_Process_ID"); + PackOut packOut = (PackOut) ctx.get("PackOutProcess"); + String sqlW = "SELECT * FROM AD_PROCESS WHERE AD_PROCESS_ID = " + + AD_Process_ID; + + AttributesImpl atts = new AttributesImpl(); + PreparedStatement pstmt1 = null; + pstmt1 = DB.prepareStatement(sqlW, getTrxName(ctx)); + try { + ResultSet rs1 = pstmt1.executeQuery(); + while (rs1.next()) { + X_AD_Process m_Process = new X_AD_Process(ctx, rs1 + .getInt("AD_Process_ID"), null); + log.log(Level.INFO, "AD_ReportView_ID: " + + rs1.getInt("AD_ReportView_ID")); + + if (rs1.getString("IsReport").equals('Y') + && rs1.getInt("AD_ReportView_ID") > 0) { + + packOut.createReportview(rs1.getInt("AD_ReportView_ID"), + atts, document); + } + if (rs1.getString("IsReport").equals('Y') + && rs1.getInt("AD_PrintFormat_ID") > 0) { + + packOut.createPrintFormat(rs1.getInt("AD_PrintFormat_ID"), + atts, document); + } + if (rs1.getInt("AD_Workflow_ID") > 0) { + + packOut.createWorkflow(rs1.getInt("AD_Workflow_ID"), atts, + document); + } + atts = createProcessBinding(atts, m_Process); + document.startElement("", "", "process", atts); + // processpara tags + String sqlP = "SELECT * FROM AD_PROCESS_PARA WHERE AD_PROCESS_ID = " + + AD_Process_ID; + PreparedStatement pstmtP = null; + pstmtP = DB.prepareStatement(sqlP, getTrxName(ctx)); + try { + ResultSet rsP = pstmtP.executeQuery(); + while (rsP.next()) { + if (rsP.getInt("AD_Reference_ID") > 0) + packOut.createReference(rsP + .getInt("AD_Reference_ID"), atts, document); + if (rsP.getInt("AD_Reference_Value_ID") > 0) + packOut.createReference(rsP + .getInt("AD_Reference_Value_ID"), atts, + document); + + createProcessPara(ctx, document, rsP + .getInt("AD_Process_Para_ID")); + } + rsP.close(); + pstmtP.close(); + pstmtP = null; + } catch (Exception e) { + log.log(Level.SEVERE, "getProcess_Para", e); + if (e instanceof SAXException) + throw (SAXException) e; + else if (e instanceof SQLException) + throw new DatabaseAccessException("Window", e); + else if (e instanceof RuntimeException) + throw (RuntimeException) e; + else + throw new RuntimeException("Window", e); + } finally { + try { + if (pstmtP != null) + pstmtP.close(); + } catch (Exception e) { + } + pstmtP = null; + } + document.endElement("", "", "process"); + } + rs1.close(); + pstmt1.close(); + pstmt1 = null; + } catch (Exception e) { + log.log(Level.SEVERE, "getProcess", e); + } finally { + try { + if (pstmt1 != null) + pstmt1.close(); + } catch (Exception e) { + } + pstmt1 = null; + } + + } + + private void createProcessPara(Properties ctx, TransformerHandler document, + int AD_Process_Para_ID) throws SAXException { + Env.setContext(ctx, X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID, + AD_Process_Para_ID); + paraHandler.create(ctx, document); + ctx.remove(X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID); + } + + private AttributesImpl createProcessBinding(AttributesImpl atts, + X_AD_Process m_Process) { + String sql = null; + String name = null; + atts.clear(); + + atts.addAttribute("", "", "Name", "CDATA", + (m_Process.getName() != null ? m_Process.getName() : "")); + + if (m_Process.getAD_Workflow_ID() > 0) { + sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?"; + name = DB.getSQLValueString(null, sql, m_Process + .getAD_Workflow_ID()); + atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", ""); + if (m_Process.getAD_Process_ID() > 0) { + sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; + name = DB + .getSQLValueString(null, sql, m_Process.getAD_Process_ID()); + atts.addAttribute("", "", "ADProcessNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADProcessNameID", "CDATA", ""); + if (m_Process.getAD_PrintFormat_ID() > 0) { + sql = "SELECT Name FROM AD_PrintFormat WHERE AD_PrintFormat_ID=?"; + name = DB.getSQLValueString(null, sql, m_Process + .getAD_PrintFormat_ID()); + atts.addAttribute("", "", "ADPrintFormatNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADPrintFormatNameID", "CDATA", ""); + if (m_Process.getAD_ReportView_ID() > 0) { + sql = "SELECT Name FROM AD_ReportView WHERE AD_ReportView_ID=?"; + name = DB.getSQLValueString(null, sql, m_Process + .getAD_ReportView_ID()); + atts.addAttribute("", "", "ADReportViewNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADReportViewNameID", "CDATA", ""); + atts.addAttribute("", "", "AccessLevel", "CDATA", (m_Process + .getAccessLevel() != null ? m_Process.getAccessLevel() : "")); + atts.addAttribute("", "", "Classname", "CDATA", (m_Process + .getClassname() != null ? m_Process.getClassname() : "")); + atts.addAttribute("", "", "Description", "CDATA", (m_Process + .getDescription() != null ? m_Process.getDescription() : "")); + atts.addAttribute("", "", "EntityType", "CDATA", (m_Process + .getEntityType() != null ? m_Process.getEntityType() : "")); + atts.addAttribute("", "", "Help", "CDATA", + (m_Process.getHelp() != null ? m_Process.getHelp() : "")); + atts.addAttribute("", "", "isBetaFunctionality", "CDATA", (m_Process + .isBetaFunctionality() == true ? "true" : "false")); + atts.addAttribute("", "", "isDirectPrint", "CDATA", (m_Process + .isDirectPrint() == true ? "true" : "false")); + atts.addAttribute("", "", "isReport", "CDATA", + (m_Process.isReport() == true ? "true" : "false")); + atts.addAttribute("", "", "isActive", "CDATA", + (m_Process.isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "ProcedureName", "CDATA", + (m_Process.getProcedureName() != null ? m_Process + .getProcedureName() : "")); + atts.addAttribute("", "", "StatisticCount", "CDATA", "0"); + atts.addAttribute("", "", "StatisticSeconds", "CDATA", "0"); + atts.addAttribute("", "", "Value", "CDATA", + (m_Process.getValue() != null ? m_Process.getValue() : "")); + atts.addAttribute("", "", "WorkflowValue", "CDATA", + (m_Process.getWorkflowValue() != null ? m_Process + .getWorkflowValue() : "")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/ProcessParaElementHandler.java b/base/src/org/adempiere/pipo/handler/ProcessParaElementHandler.java new file mode 100644 index 0000000000..59c968e5c1 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/ProcessParaElementHandler.java @@ -0,0 +1,255 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.X_AD_Process_Para; +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 ProcessParaElementHandler 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 entitytype = atts.getValue("EntityType"); + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 + && getUpdateMode(ctx).compareTo("true") == 0) { + String name = atts.getValue("Name"); + + int id = get_IDWithMaster(ctx, "AD_Process_Para", name, + "AD_Process", atts.getValue("ADProcessNameID")); + X_AD_Process_Para m_Process_para = new X_AD_Process_Para(ctx, id, + getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Process_Para", + m_Process_para); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + m_Process_para.setName(atts.getValue("Name")); + name = atts.getValue("ADProcessNameID"); + id = get_IDWithColumn(ctx, "AD_Process", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Process_para.setAD_Process_ID(id); + + name = atts.getValue("ADElementNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Element", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Process_para.setAD_Element_ID(id); + } + + name = atts.getValue("ADReferenceNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Reference", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Process_para.setAD_Reference_ID(id); + } + + name = atts.getValue("ADReferenceValueNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Reference", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Process_para.setAD_Reference_Value_ID(id); + } + + name = atts.getValue("ADValRuleNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Process_para.setAD_Val_Rule_ID(id); + } + + m_Process_para.setColumnName(atts.getValue("ColumnName")); + m_Process_para.setDefaultValue(atts.getValue("DefaultValue")); + m_Process_para.setDefaultValue2(atts.getValue("DefaultValue2")); + m_Process_para.setDescription(atts.getValue("Description") + .replaceAll("'", "''").replaceAll(",", "")); + m_Process_para.setEntityType(atts.getValue("EntityType")); + m_Process_para.setHelp(atts.getValue("Help").replaceAll("'", "''") + .replaceAll(",", "")); + m_Process_para + .setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() + : true); + m_Process_para.setName(atts.getValue("Name")); + m_Process_para.setVFormat(atts.getValue("VFormat")); + m_Process_para.setValueMax(atts.getValue("ValueMax")); + m_Process_para.setValueMin(atts.getValue("ValueMin")); + m_Process_para.setSeqNo(Integer.parseInt(atts.getValue("SeqNo"))); + m_Process_para.setFieldLength(Integer.parseInt(atts + .getValue("FieldLength"))); + m_Process_para.setIsCentrallyMaintained(Boolean.valueOf( + atts.getValue("isCentrallyMaintained")).booleanValue()); + m_Process_para.setIsMandatory(Boolean.valueOf( + atts.getValue("isMandatory")).booleanValue()); + m_Process_para.setIsRange(Boolean.valueOf(atts.getValue("isRange")) + .booleanValue()); + if (m_Process_para.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Process_para.getName(), "Process_para", + m_Process_para.get_ID(), AD_Backup_ID, Object_Status, + "AD_Process_para", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Process_para")); + } else { + record_log(ctx, 0, m_Process_para.getName(), "Process_para", + m_Process_para.get_ID(), AD_Backup_ID, Object_Status, + "AD_Process_para", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Process_para")); + throw new POSaveFailedException("ProcessPara"); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Process_Para_ID = Env.getContextAsInt(ctx, + X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID); + X_AD_Process_Para m_Processpara = new X_AD_Process_Para(ctx, + AD_Process_Para_ID, getTrxName(ctx)); + AttributesImpl atts = new AttributesImpl(); + createProcessParaBinding(atts, m_Processpara); + document.startElement("", "", "processpara", atts); + document.endElement("", "", "processpara"); + } + + private AttributesImpl createProcessParaBinding(AttributesImpl atts, + X_AD_Process_Para m_Processpara) { + String sql = null; + String name = null; + atts.clear(); + atts + .addAttribute("", "", "Name", "CDATA", + (m_Processpara.getName() != null ? m_Processpara + .getName() : "")); + if (m_Processpara.getAD_Process_ID() > 0) { + sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; + name = DB.getSQLValueString(null, sql, m_Processpara + .getAD_Process_ID()); + atts.addAttribute("", "", "ADProcessNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADProcessNameID", "CDATA", ""); + if (m_Processpara.getAD_Process_Para_ID() > 0) { + sql = "SELECT Name FROM AD_Process_Para WHERE AD_Process_Para_ID=?"; + name = DB.getSQLValueString(null, sql, m_Processpara + .getAD_Process_Para_ID()); + atts.addAttribute("", "", "ADProcessParaNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADProcessParaNameID", "CDATA", ""); + if (m_Processpara.getAD_Element_ID() > 0) { + sql = "SELECT Name FROM AD_Element WHERE AD_Element_ID=?"; + name = DB.getSQLValueString(null, sql, m_Processpara + .getAD_Element_ID()); + atts.addAttribute("", "", "ADElementNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADElementNameID", "CDATA", ""); + if (m_Processpara.getAD_Reference_ID() > 0) { + sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; + name = DB.getSQLValueString(null, sql, m_Processpara + .getAD_Reference_ID()); + atts.addAttribute("", "", "ADReferenceNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADReferenceNameID", "CDATA", ""); + if (m_Processpara.getAD_Reference_Value_ID() > 0) { + sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; + name = DB.getSQLValueString(null, sql, m_Processpara + .getAD_Reference_Value_ID()); + atts.addAttribute("", "", "ADReferenceValueNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADReferenceValueNameID", "CDATA", ""); + if (m_Processpara.getAD_Val_Rule_ID() > 0) { + sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?"; + name = DB.getSQLValueString(null, sql, m_Processpara + .getAD_Val_Rule_ID()); + atts.addAttribute("", "", "ADValRuleNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADValRuleNameID", "CDATA", ""); + atts.addAttribute("", "", "ColumnName", "CDATA", (m_Processpara + .getColumnName() != null ? m_Processpara.getColumnName() : "")); + atts.addAttribute("", "", "DefaultValue", "CDATA", (m_Processpara + .getDefaultValue() != null ? m_Processpara.getDefaultValue() + : "")); + atts.addAttribute("", "", "DefaultValue2", "CDATA", (m_Processpara + .getDefaultValue2() != null ? m_Processpara.getDefaultValue2() + : "")); + atts.addAttribute("", "", "Description", "CDATA", + (m_Processpara.getDescription() != null ? m_Processpara + .getDescription() : "")); + atts.addAttribute("", "", "EntityType", "CDATA", (m_Processpara + .getEntityType() != null ? m_Processpara.getEntityType() : "")); + atts + .addAttribute("", "", "Help", "CDATA", + (m_Processpara.getHelp() != null ? m_Processpara + .getHelp() : "")); + atts.addAttribute("", "", "isActive", "CDATA", (m_Processpara + .isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "VFormat", "CDATA", (m_Processpara + .getVFormat() != null ? m_Processpara.getVFormat() : "")); + atts.addAttribute("", "", "ValueMax", "CDATA", (m_Processpara + .getValueMax() != null ? m_Processpara.getValueMax() : "")); + atts.addAttribute("", "", "ValueMin", "CDATA", (m_Processpara + .getValueMin() != null ? m_Processpara.getValueMin() : "")); + atts.addAttribute("", "", "SeqNo", "CDATA", + (m_Processpara.getSeqNo() > 0 ? "" + m_Processpara.getSeqNo() + : "0")); + atts.addAttribute("", "", "FieldLength", "CDATA", (m_Processpara + .getFieldLength() > 0 ? "" + m_Processpara.getFieldLength() + : "0")); + atts.addAttribute("", "", "isCentrallyMaintained", "CDATA", + (m_Processpara.isCentrallyMaintained() == true ? "true" + : "false")); + atts.addAttribute("", "", "isMandatory", "CDATA", (m_Processpara + .isMandatory() == true ? "true" : "false")); + atts.addAttribute("", "", "isRange", "CDATA", + (m_Processpara.isRange() == true ? "true" : "false")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/ReferenceElementHandler.java b/base/src/org/adempiere/pipo/handler/ReferenceElementHandler.java new file mode 100644 index 0000000000..698854b28c --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/ReferenceElementHandler.java @@ -0,0 +1,260 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.X_AD_Ref_List; +import org.compiere.model.X_AD_Ref_Table; +import org.compiere.model.X_AD_Reference; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +public class ReferenceElementHandler extends AbstractElementHandler { + + private ReferenceListElementHandler listHandler = new ReferenceListElementHandler(); + private ReferenceTableElementHandler tableHandler = new ReferenceTableElementHandler(); + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("name")); + + String entitytype = atts.getValue("EntityType"); + String name = atts.getValue("name"); + + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 + && getUpdateMode(ctx).compareTo("true") == 0) { + int id = get_ID(ctx, "AD_Reference", name); + + X_AD_Reference m_Reference = new X_AD_Reference(ctx, id, + getTrxName(ctx)); + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Reference", m_Reference); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + + m_Reference.setDescription(atts.getValue("Description").replaceAll( + "'", "''").replaceAll(",", "")); + m_Reference.setEntityType(atts.getValue("EntityType")); + m_Reference.setHelp(atts.getValue("Help").replaceAll("'", "''") + .replaceAll(",", "")); + m_Reference.setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() : true); + m_Reference.setName(atts.getValue("name")); + + // m_Reference.setVFormat(atts.getValue("VFormat")); + m_Reference.setValidationType(atts.getValue("ValidationType")); + if (m_Reference.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Reference.getName(), "Reference", + m_Reference.get_ID(), AD_Backup_ID, Object_Status, + "AD_Reference", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Reference")); + } else { + record_log(ctx, 0, m_Reference.getName(), "Reference", + m_Reference.get_ID(), AD_Backup_ID, Object_Status, + "AD_Reference", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Reference")); + throw new POSaveFailedException("Reference"); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int Reference_id = Env.getContextAsInt(ctx, + X_AD_Reference.COLUMNNAME_AD_Reference_ID); + AttributesImpl atts = new AttributesImpl(); + String sql = "SELECT * FROM AD_Reference WHERE AD_Reference_ID= " + + Reference_id; + + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + + try { + + ResultSet rs = pstmt.executeQuery(); + + while (rs.next()) { + + X_AD_Reference m_Reference = new X_AD_Reference(ctx, rs + .getInt("AD_Reference_ID"), null); + createReferenceBinding(atts, m_Reference); + document.startElement("", "", "reference", atts); + + if (m_Reference.getValidationType().compareTo("L") == 0) { + String sql1 = "SELECT * FROM AD_Ref_List WHERE AD_Reference_ID= " + + Reference_id; + + PreparedStatement pstmt1 = null; + pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx)); + + try { + + ResultSet rs1 = pstmt1.executeQuery(); + + while (rs1.next()) { + createReferenceList(ctx, document, rs1 + .getInt("AD_REF_LIST_ID")); + } + rs1.close(); + pstmt1.close(); + pstmt1 = null; + } + + catch (Exception e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + if (e instanceof SAXException) + throw (SAXException) e; + else if (e instanceof SQLException) + throw new DatabaseAccessException("Window", e); + else if (e instanceof RuntimeException) + throw (RuntimeException) e; + else + throw new RuntimeException("Window", e); + } finally { + try { + if (pstmt1 != null) + pstmt1.close(); + } catch (Exception e) { + } + pstmt1 = null; + } + + } else if (m_Reference.getValidationType().compareTo("T") == 0) { + String sql1 = "SELECT AD_Reference_ID FROM AD_Ref_Table WHERE AD_Reference_ID = " + + Reference_id; + PreparedStatement pstmt1 = null; + pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx)); + + try { + + ResultSet rs1 = pstmt1.executeQuery(); + + while (rs1.next()) { + createReferenceTable(ctx, document, Reference_id); + } + rs1.close(); + pstmt1.close(); + pstmt1 = null; + } + + catch (Exception e) { + log.log(Level.SEVERE, "getRef_Table", e); + } + + finally { + try { + if (pstmt1 != null) + pstmt1.close(); + } catch (Exception e) { + } + pstmt1 = null; + } + } + document.endElement("", "", "reference"); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e) { + log.log(Level.SEVERE, "getRefence", e); + } + + finally { + try { + if (pstmt != null) + pstmt.close(); + } catch (Exception e) { + } + pstmt = null; + } + + } + + private void createReferenceTable(Properties ctx, TransformerHandler document, + int reference_id) throws SAXException { + Env.setContext(ctx, X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID, reference_id); + tableHandler.create(ctx, document); + ctx.remove(X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID); + } + + private void createReferenceList(Properties ctx, + TransformerHandler document, int AD_Ref_List_ID) + throws SAXException { + Env.setContext(ctx, X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID, + AD_Ref_List_ID); + listHandler.create(ctx, document); + ctx.remove(X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID); + } + + private AttributesImpl createReferenceBinding(AttributesImpl atts, + X_AD_Reference m_Reference) { + String sql = null; + String name = null; + atts.clear(); + if (m_Reference.getAD_Reference_ID() > 0) { + sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; + name = DB.getSQLValueString(null, sql, m_Reference + .getAD_Reference_ID()); + atts.addAttribute("", "", "name", "CDATA", name); + } else + atts.addAttribute("", "", "name", "CDATA", ""); + atts.addAttribute("", "", "Description", "CDATA", (m_Reference + .getDescription() != null ? m_Reference.getDescription() : "")); + atts.addAttribute("", "", "EntityType", "CDATA", (m_Reference + .getEntityType() != null ? m_Reference.getEntityType() : "")); + atts.addAttribute("", "", "Help", "CDATA", + (m_Reference.getHelp() != null ? m_Reference.getHelp() : "")); + atts.addAttribute("", "", "Name", "CDATA", + (m_Reference.getName() != null ? m_Reference.getName() : "")); + atts.addAttribute("", "", "isActive", "CDATA", + (m_Reference.isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "VFormat", "CDATA", + (m_Reference.getVFormat() != null ? m_Reference.getVFormat() + : "")); + atts.addAttribute("", "", "ValidationType", "CDATA", (m_Reference + .getValidationType() != null ? m_Reference.getValidationType() + : "")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/ReferenceListElementHandler.java b/base/src/org/adempiere/pipo/handler/ReferenceListElementHandler.java new file mode 100644 index 0000000000..bfbac99f42 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/ReferenceListElementHandler.java @@ -0,0 +1,141 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.X_AD_Ref_List; +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 ReferenceListElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("Name")); + // TODO: Solve for date issues with valuefrom valueto + String entitytype = atts.getValue("EntityType"); + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 + && getUpdateMode(ctx).compareTo("true") == 0) { + String name = atts.getValue("Name"); + int Referenceid = get_IDWithColumn(ctx, "AD_Reference", "Name", + atts.getValue("ADRefenceNameID")); + int id = get_IDWithMaster(ctx, "AD_Ref_List", name, "AD_Reference", + Referenceid); + X_AD_Ref_List m_Ref_List = new X_AD_Ref_List(ctx, id, + getTrxName(ctx)); + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Ref_List", m_Ref_List); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + name = atts.getValue("ADRefenceNameID"); + id = get_IDWithColumn(ctx, "AD_Reference", "Name", name); + m_Ref_List.setAD_Reference_ID(id); + m_Ref_List.setDescription(atts.getValue("Description").replaceAll( + "'", "''").replaceAll(",", "")); + m_Ref_List.setEntityType(atts.getValue("EntityType")); + m_Ref_List.setName(atts.getValue("Name")); + m_Ref_List.setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() : true); + m_Ref_List.setValue(atts.getValue("Value")); + if (m_Ref_List.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Ref_List.getName(), "Reference List", + m_Ref_List.get_ID(), AD_Backup_ID, Object_Status, + "AD_Ref_List", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Ref_List")); + } else { + record_log(ctx, 0, m_Ref_List.getName(), "Reference List", + m_Ref_List.get_ID(), AD_Backup_ID, Object_Status, + "AD_Ref_List", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Ref_List")); + throw new POSaveFailedException("ReferenceList"); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Ref_List_ID = Env.getContextAsInt(ctx, + X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID); + X_AD_Ref_List m_Ref_List = new X_AD_Ref_List(ctx, AD_Ref_List_ID, + getTrxName(ctx)); + AttributesImpl atts = new AttributesImpl(); + createRefListBinding(atts, m_Ref_List); + document.startElement("", "", "referencelist", atts); + document.endElement("", "", "referencelist"); + } + + private AttributesImpl createRefListBinding(AttributesImpl atts, + X_AD_Ref_List m_Ref_List) { + String sql = null; + String name = null; + atts.clear(); + if (m_Ref_List.getAD_Ref_List_ID() > 0) { + sql = "SELECT Name FROM AD_Ref_List WHERE AD_Ref_List_ID=?"; + name = DB.getSQLValueString(null, sql, m_Ref_List + .getAD_Ref_List_ID()); + } + if (name != null) + atts.addAttribute("", "", "ADReflistNameID", "CDATA", name); + else + atts.addAttribute("", "", "ADReflistNameID", "CDATA", ""); + if (m_Ref_List.getAD_Reference_ID() > 0) { + sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; + name = DB.getSQLValueString(null, sql, m_Ref_List + .getAD_Reference_ID()); + } + if (name != null) + atts.addAttribute("", "", "ADRefenceNameID", "CDATA", name); + else + atts.addAttribute("", "", "ADRefenceNameID", "CDATA", ""); + atts.addAttribute("", "", "Description", "CDATA", (m_Ref_List + .getDescription() != null ? m_Ref_List.getDescription() : "")); + atts.addAttribute("", "", "EntityType", "CDATA", (m_Ref_List + .getEntityType() != null ? m_Ref_List.getEntityType() : "")); + atts.addAttribute("", "", "Name", "CDATA", + (m_Ref_List.getName() != null ? m_Ref_List.getName() : "")); + atts.addAttribute("", "", "isActive", "CDATA", + (m_Ref_List.isActive() == true ? "true" : "false")); + // atts.addAttribute("","","ValidFrom","CDATA",(m_Ref_List.getValidFrom + // ().toGMTString() != null ? + // m_Ref_List.getValidFrom().toGMTString():"")); + // atts.addAttribute("","","ValidTo","CDATA",(m_Ref_List.getValidTo + // ().toGMTString() != null ? + // m_Ref_List.getValidTo().toGMTString():"")); + atts.addAttribute("", "", "Value", "CDATA", + (m_Ref_List.getValue() != null ? m_Ref_List.getValue() : "")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/ReferenceTableElementHandler.java b/base/src/org/adempiere/pipo/handler/ReferenceTableElementHandler.java new file mode 100644 index 0000000000..cb3710176b --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/ReferenceTableElementHandler.java @@ -0,0 +1,275 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.MColumn; +import org.compiere.model.MTable; +import org.compiere.model.X_AD_Ref_Table; +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 ReferenceTableElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + + log.info(elementValue); + Attributes atts = element.attributes; + String entitytype = atts.getValue("EntityType"); + String name = atts.getValue("ADRefenceNameID"); + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 + && getUpdateMode(ctx).compareTo("true") == 0) { + StringBuffer sqlB = new StringBuffer( + "SELECT AD_Reference_ID FROM AD_Reference WHERE Name= ?"); + int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name); + sqlB = new StringBuffer( + "SELECT Count(*) FROM AD_Ref_Table WHERE AD_Reference_ID= ?"); + int count = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), id); + int tableId = get_IDWithColumn(ctx, "AD_Table", "TableName", atts + .getValue("ADTableNameID")); + if (tableId == 0) { + MTable m_Table = new MTable(ctx, 0, getTrxName(ctx)); + m_Table.setAccessLevel("3"); + m_Table.setName(atts.getValue("ADTableNameID")); + m_Table.setTableName(atts.getValue("ADTableNameID")); + if (m_Table.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Table.getName(), "Table", m_Table + .get_ID(), 0, "New", "AD_Table", get_IDWithColumn( + ctx, "AD_Table", "TableName", "AD_Table")); + } else { + record_log(ctx, 0, m_Table.getName(), "Table", m_Table + .get_ID(), 0, "New", "AD_Table", get_IDWithColumn( + ctx, "AD_Table", "TableName", "AD_Table")); + } + tableId = get_IDWithColumn(ctx, "AD_Table", "TableName", atts + .getValue("ADTableNameID")); + } + name = atts.getValue("ADDisplay"); + int DisplayId = get_IDWithMasterAndColumn(ctx, "AD_Column", + "ColumnName", name, "AD_Table", tableId); + if (DisplayId == 0) { + MColumn m_Column = new MColumn(ctx, 0, getTrxName(ctx)); + m_Column.setAD_Table_ID(tableId); + // m_Column.setVersion(new BigDecimal("1")); // use constructor + // value + m_Column.setColumnName(name); + m_Column.setName(name); + m_Column.setAD_Reference_ID(30); + if (m_Column.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Column.getName(), "Column", m_Column + .get_ID(), 0, "New", "AD_Column", get_IDWithColumn( + ctx, "AD_Table", "TableName", "AD_Column")); + } else { + record_log(ctx, 0, m_Column.getName(), "Column", m_Column + .get_ID(), 0, "New", "AD_Column", get_IDWithColumn( + ctx, "AD_Table", "TableName", "AD_Column")); + } + } + name = atts.getValue("Key"); + int keyId = get_IDWithMasterAndColumn(ctx, "AD_Column", + "ColumnName", name, "AD_Table", tableId); + if (keyId == 0) { + MColumn m_Column = new MColumn(ctx, 0, getTrxName(ctx)); + m_Column.setAD_Table_ID(tableId); + // m_Column.setVersion(new BigDecimal("1")); // use constructor + // value + m_Column.setColumnName(name); + m_Column.setName(name); + m_Column.setAD_Reference_ID(30); + if (m_Column.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Column.getName(), "Column", m_Column + .get_ID(), 0, "New", "AD_Column", get_IDWithColumn( + ctx, "AD_Table", "TableName", "AD_Column")); + } else { + record_log(ctx, 0, m_Column.getName(), "Column", m_Column + .get_ID(), 0, "New", "AD_Column", get_IDWithColumn( + ctx, "AD_Table", "TableName", "AD_Column")); + } + } + + name = atts.getValue("ADDisplay"); + DisplayId = get_IDWithMasterAndColumn(ctx, "AD_Column", + "ColumnName", name, "AD_Table", tableId); + name = atts.getValue("Key"); + keyId = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", + name, "AD_Table", tableId); + String entityType = atts.getValue("EntityType"); + String isValueDisplayed = atts.getValue("IsValueDisplayed"); + String OrderByClause = atts.getValue("OrderByClause").replaceAll( + "'", "''").replaceAll(",", ""); + String WhereClause = atts.getValue("WhereClause").replaceAll("'", + "''").replaceAll(",", ""); + if (count > 0) { + sqlB = new StringBuffer("UPDATE AD_Ref_Table ").append( + "SET AD_Table_ID = " + tableId).append( + ", AD_Display = " + DisplayId).append( + ", AD_Key = " + keyId).append( + ", isValueDisplayed = '" + isValueDisplayed).append( + "', OrderByClause = '" + OrderByClause).append( + "', EntityType ='" + entityType).append( + "', WhereClause = '" + WhereClause).append( + "' WHERE AD_Reference_ID = " + id); + + int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx)); + if (no > 0) { + record_log(ctx, 1, atts.getValue("ADRefenceNameID"), + "Reference Table", id, 0, "Update", "AD_Ref_Table", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Ref_Table")); + } else { + record_log(ctx, 0, atts.getValue("ADRefenceNameID"), + "Reference Table", id, 0, "Update", "AD_Ref_Table", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Ref_Table")); + throw new POSaveFailedException("ReferenceTable"); + } + } else { + sqlB = new StringBuffer("Insert INTO AD_Ref_Table") + .append( + "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ") + .append( + "AD_Reference_ID, AD_Table_ID, AD_Display, AD_Key ") + .append( + ",entityType, isValueDisplayed, OrderByClause, ") + .append(" WhereClause )").append( + "VALUES(0, 0, 0, 0, " + id).append( + ", " + tableId).append(", " + DisplayId) + .append(", " + keyId).append(", '" + entityType) + .append("', '" + isValueDisplayed).append( + "', '" + OrderByClause).append( + "', '" + WhereClause + "')"); + + int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx)); + if (no > 0) { + record_log(ctx, 1, atts.getValue("ADRefenceNameID"), + "Reference Table", id, 0, "New", "AD_Ref_Table", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Ref_Table")); + } else { + record_log(ctx, 0, atts.getValue("ADRefenceNameID"), + "Reference Table", id, 0, "New", "AD_Ref_Table", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Ref_Table")); + throw new POSaveFailedException("ReferenceTable"); + } + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int Reference_id = Env.getContextAsInt(ctx, + X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID); + AttributesImpl atts = new AttributesImpl(); + createReferenceTableBinding(ctx, atts, Reference_id); + document.startElement("", "", "referencetable", atts); + document.endElement("", "", "referencetable"); + } + + private AttributesImpl createReferenceTableBinding(Properties ctx, + AttributesImpl atts, int reference_ID) { + atts.clear(); + String name = null; + String sql = null; + String sql1 = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID= " + + reference_ID; + + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement(sql1, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) { + sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; + name = DB.getSQLValueString(null, sql, reference_ID); + atts.addAttribute("", "", "ADRefenceNameID", "CDATA", name); + + if (rs.getInt("AD_Table_ID") > 0) { + sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; + name = DB.getSQLValueString(null, sql, rs + .getInt("AD_Table_ID")); + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADTableNameID", "CDATA", ""); + + if (rs.getInt("AD_Display") > 0) { + sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null, sql, rs + .getInt("AD_Display")); + atts.addAttribute("", "", "ADDisplay", "CDATA", name); + } else + atts.addAttribute("", "", "ADDisplay", "CDATA", ""); + + if (rs.getInt("AD_Key") > 0) { + sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null, sql, rs.getInt("AD_Key")); + atts.addAttribute("", "", "Key", "CDATA", name); + } else + atts.addAttribute("", "", "Key", "CDATA", ""); + atts.addAttribute("", "", "EntityType", "CDATA", (rs + .getString("EntityType") != null ? rs + .getString("EntityType") : "")); + atts + .addAttribute("", "", "IsValueDisplayed", "CDATA", + (rs.getString("IsValueDisplayed") + .compareTo("Y") == 0 ? "Y" : "N")); + atts.addAttribute("", "", "OrderByClause", "CDATA", (rs + .getString("OrderByClause") != null ? rs + .getString("OrderByClause") : "")); + atts.addAttribute("", "", "isActive", "CDATA", (rs.getString( + "isActive").compareTo("Y") == 0 ? "Y" : "N")); + atts.addAttribute("", "", "WhereClause", "CDATA", (rs + .getString("WhereClause") != null ? rs + .getString("WhereClause") : "")); + + } + rs.close(); + pstmt.close(); + pstmt = null; + } catch (Exception e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + throw new DatabaseAccessException("ReferenceTable", e); + } finally { + try { + if (pstmt != null) + pstmt.close(); + } catch (Exception e) { + } + pstmt = null; + } + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/ReportViewColElementHandler.java b/base/src/org/adempiere/pipo/handler/ReportViewColElementHandler.java new file mode 100644 index 0000000000..304db6316a --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/ReportViewColElementHandler.java @@ -0,0 +1,155 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.X_AD_ReportView_Col; +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 ReportViewColElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("ADReportViewColID")); + + String entitytype = atts.getValue("EntityType"); + String name = atts.getValue("ADReportViewColID"); + + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 + && getUpdateMode(ctx).compareTo("true") == 0) { + int id = get_ID(ctx, "AD_Reportview_Col", name); + X_AD_ReportView_Col m_Reportview_Col = new X_AD_ReportView_Col(ctx, + id, getTrxName(ctx)); + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Reportview_Col", + m_Reportview_Col); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + name = atts.getValue("ADReportviewnameID"); + id = get_IDWithColumn(ctx, "AD_ReportView", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Reportview_Col.setAD_ReportView_ID(id); + + name = atts.getValue("ADColumnNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Column", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Reportview_Col.setAD_Column_ID(id); + } + + m_Reportview_Col.setFunctionColumn(atts.getValue("ADColumnNameID")); + m_Reportview_Col + .setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() + : true); + m_Reportview_Col.setIsGroupFunction(Boolean.valueOf( + atts.getValue("ADColumnNameID")).booleanValue()); + if (m_Reportview_Col.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, "" + m_Reportview_Col.getAD_ReportView_ID(), + "Reportview_Col", m_Reportview_Col.get_ID(), + AD_Backup_ID, Object_Status, "AD_Reportview_Col", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Reportview_Col")); + } else { + record_log(ctx, 0, "" + m_Reportview_Col.getAD_ReportView_ID(), + "Reportview_Col", m_Reportview_Col.get_ID(), + AD_Backup_ID, Object_Status, "AD_Reportview_Col", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Reportview_Col")); + throw new POSaveFailedException("ReportViewCol"); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_ReportView_Col_ID = Env.getContextAsInt(ctx, + X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID); + X_AD_ReportView_Col m_Reportview_Col = new X_AD_ReportView_Col(ctx, + AD_ReportView_Col_ID, getTrxName(ctx)); + AttributesImpl atts = new AttributesImpl(); + createReportViewColBinding(atts, m_Reportview_Col); + document.startElement("", "", "reportviewcol", atts); + document.endElement("", "", "reportviewcol"); + } + + private AttributesImpl createReportViewColBinding(AttributesImpl atts, + X_AD_ReportView_Col m_Reportview_Col) { + String sql = null; + String name = null; + atts.clear(); + if (m_Reportview_Col.getAD_Column_ID() > 0) { + sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null, sql, m_Reportview_Col + .getAD_Column_ID()); + atts.addAttribute("", "", "ADColumnNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADColumnNameID", "CDATA", ""); + + if (m_Reportview_Col.getAD_ReportView_ID() > 0) { + sql = "SELECT Name FROM AD_Reference WHERE AD_Reportview_ID=?"; + name = DB.getSQLValueString(null, sql, m_Reportview_Col + .getAD_ReportView_ID()); + atts.addAttribute("", "", "ADReportviewnameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADColumnNameID", "CDATA", ""); + + if (m_Reportview_Col.getAD_ReportView_Col_ID() > 0) { + sql = "SELECT Name FROM AD_Reference WHERE AD_ReportView_Col_ID=?"; + name = DB.getSQLValueString(null, sql, m_Reportview_Col + .getAD_ReportView_Col_ID()); + atts.addAttribute("", "", "ADReportViewColID", "CDATA", name); + } else + atts.addAttribute("", "", "ADColumnNameID", "CDATA", ""); + + atts.addAttribute("", "", "FunctionColumn", "CDATA", (m_Reportview_Col + .getFunctionColumn() != null ? m_Reportview_Col + .getFunctionColumn() : "")); + atts.addAttribute("", "", "isActive", "CDATA", (m_Reportview_Col + .isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "isGroupFunction", "CDATA", (m_Reportview_Col + .isGroupFunction() == true ? "true" : "false")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/ReportViewElementHandler.java b/base/src/org/adempiere/pipo/handler/ReportViewElementHandler.java new file mode 100644 index 0000000000..5c59c96816 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/ReportViewElementHandler.java @@ -0,0 +1,255 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.PackOut; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.MTable; +import org.compiere.model.X_AD_ReportView; +import org.compiere.model.X_AD_ReportView_Col; +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 ReportViewElementHandler extends AbstractElementHandler { + + private ReportViewColElementHandler columnHandler = new ReportViewColElementHandler(); + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("ADReportviewnameID")); + String entitytype = atts.getValue("EntityType"); + String name = atts.getValue("ADReportviewnameID"); + + int id = get_ID(ctx, "AD_ReportView", name); + X_AD_ReportView m_Reportview = new X_AD_ReportView(ctx, id, + getTrxName(ctx)); + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Reportview", m_Reportview); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + String Name = atts.getValue("ADTableNameID"); + id = get_IDWithColumn(ctx, "AD_Table", "TableName", Name); + MTable m_Table = null; + if (id == 0) { + m_Table = new MTable(ctx, 0, getTrxName(ctx)); + m_Table.setAccessLevel("3"); + m_Table.setName(Name); + m_Table.setTableName(Name); + if (m_Table.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Table.getName(), "Table", + m_Table.get_ID(), 0, "New", "AD_Table", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Table")); + } else { + record_log(ctx, 0, m_Table.getName(), "Table", + m_Table.get_ID(), 0, "New", "AD_Table", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Table")); + } + id = get_IDWithColumn(ctx, "AD_Table", "TableName", Name); + } + + m_Reportview.setAD_Table_ID(id); + m_Reportview.setDescription(atts.getValue("Description").replaceAll( + "'", "''").replaceAll(",", "")); + m_Reportview.setEntityType(atts.getValue("EntityType")); + m_Reportview.setName(atts.getValue("Name")); + m_Reportview.setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() : true); + m_Reportview.setOrderByClause(atts.getValue("OrderByClause")); + m_Reportview.setWhereClause(atts.getValue("WhereClause")); + if (m_Reportview.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Reportview.getName(), "Reportview", + m_Reportview.get_ID(), AD_Backup_ID, Object_Status, + "AD_Reportview", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Reportview")); + } else { + record_log(ctx, 0, m_Reportview.getName(), "Reportview", + m_Reportview.get_ID(), AD_Backup_ID, Object_Status, + "AD_Reportview", get_IDWithColumn(ctx, "AD_Table", + "TableName", "AD_Reportview")); + throw new POSaveFailedException("ReportView"); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + PackOut packOut = (PackOut) ctx.get("PackOutProcess"); + int AD_ReportView_ID = Env.getContextAsInt(ctx, "AD_ReportView_ID"); + String sql = "SELECT * FROM AD_ReportView WHERE AD_ReportView_ID= " + + AD_ReportView_ID; + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + AttributesImpl atts = new AttributesImpl(); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + X_AD_ReportView m_Reportview = new X_AD_ReportView(ctx, rs + .getInt("AD_Reportview_ID"), null); + atts = createReportViewBinding(atts, m_Reportview); + document.startElement("", "", "reportview", atts); + document.endElement("", "", "reportview"); + + String sql1 = "SELECT * FROM AD_Printformat WHERE AD_Reportview_ID= " + + AD_ReportView_ID; + PreparedStatement pstmt1 = null; + pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx)); + try { + ResultSet rs1 = pstmt1.executeQuery(); + while (rs1.next()) { + // Export Table if neccessary + packOut.createTable(rs1.getInt("AD_Table_ID"), atts, + document); + packOut.createPrintFormat(rs1 + .getInt("AD_Printformat_ID"), atts, document); + } + rs1.close(); + pstmt1.close(); + pstmt1 = null; + } finally { + try { + if (pstmt1 != null) + pstmt1.close(); + } catch (Exception e) { + } + pstmt1 = null; + } + atts.clear(); + sql1 = "SELECT * FROM AD_ReportView_Col WHERE AD_Reportview_ID= " + + AD_ReportView_ID; + pstmt1 = null; + pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx)); + try { + ResultSet rs1 = pstmt1.executeQuery(); + while (rs1.next()) { + createReportViewCol(ctx, document, rs1 + .getInt("AD_ReportView_Col_ID")); + } + rs1.close(); + pstmt1.close(); + pstmt1 = null; + } finally { + try { + if (pstmt1 != null) + pstmt1.close(); + } catch (Exception e) { + } + pstmt1 = null; + } + } + + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e) { + log.log(Level.SEVERE, "reportview", e); + if (e instanceof SAXException) + throw (SAXException) e; + else if (e instanceof SQLException) + throw new DatabaseAccessException("Window", e); + else if (e instanceof RuntimeException) + throw (RuntimeException) e; + else + throw new RuntimeException("Window", e); + } finally { + try { + if (pstmt != null) + pstmt.close(); + } catch (Exception e) { + } + pstmt = null; + } + } + + private void createReportViewCol(Properties ctx, + TransformerHandler document, int AD_ReportView_Col_ID) + throws SAXException { + Env.setContext(ctx, + X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID, + AD_ReportView_Col_ID); + columnHandler.create(ctx, document); + ctx.remove(X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID); + } + + private AttributesImpl createReportViewBinding(AttributesImpl atts, + X_AD_ReportView m_Reportview) { + String sql = null; + String name = null; + atts.clear(); + + if (m_Reportview.getAD_ReportView_ID() > 0) { + sql = "SELECT Name FROM AD_ReportView WHERE AD_ReportView_ID=?"; + name = DB.getSQLValueString(null, sql, m_Reportview + .getAD_ReportView_ID()); + atts.addAttribute("", "", "ADReportviewnameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADReportviewnameID", "CDATA", ""); + + if (m_Reportview.getAD_Table_ID() > 0) { + sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; + name = DB.getSQLValueString(null, sql, m_Reportview + .getAD_Table_ID()); + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADTableNameID", "CDATA", ""); + + atts + .addAttribute("", "", "Description", "CDATA", (m_Reportview + .getDescription() != null ? m_Reportview + .getDescription() : "")); + atts.addAttribute("", "", "EntityType", "CDATA", (m_Reportview + .getEntityType() != null ? m_Reportview.getEntityType() : "")); + atts.addAttribute("", "", "Name", "CDATA", + (m_Reportview.getName() != null ? m_Reportview.getName() : "")); + atts.addAttribute("", "", "isActive", "CDATA", + (m_Reportview.isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "OrderByClause", "CDATA", (m_Reportview + .getOrderByClause() != null ? m_Reportview.getOrderByClause() + : "")); + atts + .addAttribute("", "", "WhereClause", "CDATA", (m_Reportview + .getWhereClause() != null ? m_Reportview + .getWhereClause() : "")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/RoleElementHandler.java b/base/src/org/adempiere/pipo/handler/RoleElementHandler.java new file mode 100644 index 0000000000..f2b052ff40 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/RoleElementHandler.java @@ -0,0 +1,479 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.MRole; +import org.compiere.model.X_AD_Form; +import org.compiere.model.X_AD_Package_Exp_Detail; +import org.compiere.model.X_AD_Process; +import org.compiere.model.X_AD_Role; +import org.compiere.model.X_AD_Task; +import org.compiere.model.X_AD_User; +import org.compiere.model.X_AD_Window; +import org.compiere.model.X_AD_Workflow; +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 RoleElementHandler extends AbstractElementHandler { + + private OrgRoleElementHandler orgHandler = new OrgRoleElementHandler(); + private ProcessAccessElementHandler processHandler = new ProcessAccessElementHandler(); + private UserRoleElementHandler userHandler = new UserRoleElementHandler(); + private WindowAccessElementHandler windowHandler = new WindowAccessElementHandler(); + private FormAccessElementHandler formHandler = new FormAccessElementHandler(); + private TaskAccessElementHandler taskHandler = new TaskAccessElementHandler(); + private WorkflowAccessElementHandler workflowHandler = new WorkflowAccessElementHandler(); + + public void startElement(Properties ctx, Element element) + throws SAXException { + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("Name")); + + String name = atts.getValue("Name"); + + int id = get_ID(ctx, "AD_Role", name); + MRole m_Role = new MRole(ctx, id, getTrxName(ctx)); + + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Role", m_Role); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + + m_Role.setName(name); + name = atts.getValue("treemenuname"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Tree", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Role.setAD_Tree_Menu_ID(id); + } + + name = atts.getValue("treeorgname"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Tree", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Role.setAD_Tree_Org_ID(id); + } + + name = atts.getValue("currencycode"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "C_Currency", "ISO_Code", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Role.setC_Currency_ID(id); + } + + name = atts.getValue("supervisorid"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_User", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Role.setC_Currency_ID(id); + } + + m_Role.setDescription(atts.getValue("Description") + .replaceAll("'", "''").replaceAll(",", "")); + m_Role.setAmtApproval(new BigDecimal(atts.getValue("AmtApproval"))); + m_Role.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf( + atts.getValue("isActive")).booleanValue() : true); + m_Role + .setIsAccessAllOrgs(atts.getValue("isAccessAllOrgs") != null ? Boolean + .valueOf(atts.getValue("isAccessAllOrgs")) + .booleanValue() + : true); + m_Role + .setIsCanApproveOwnDoc(atts.getValue("isCanApproveOwnDoc") != null ? Boolean + .valueOf(atts.getValue("isCanApproveOwnDoc")) + .booleanValue() + : true); + m_Role.setIsCanExport(atts.getValue("isCanExport") != null ? Boolean + .valueOf(atts.getValue("isCanExport")).booleanValue() : true); + m_Role.setIsCanReport(atts.getValue("isCanReport") != null ? Boolean + .valueOf(atts.getValue("isCanReport")).booleanValue() : true); + m_Role.setIsChangeLog(atts.getValue("isChangeLog") != null ? Boolean + .valueOf(atts.getValue("isChangeLog")).booleanValue() : true); + m_Role.setIsManual(atts.getValue("isManual") != null ? Boolean.valueOf( + atts.getValue("isManual")).booleanValue() : true); + m_Role + .setIsPersonalAccess(atts.getValue("isPersonalAccess") != null ? Boolean + .valueOf(atts.getValue("isPersonalAccess")) + .booleanValue() + : true); + m_Role + .setIsPersonalLock(atts.getValue("isPersonalLock") != null ? Boolean + .valueOf(atts.getValue("isPersonalLock")) + .booleanValue() + : true); + m_Role.setIsShowAcct(atts.getValue("isShowAcct") != null ? Boolean + .valueOf(atts.getValue("isShowAcct")).booleanValue() : true); + m_Role + .setIsUseUserOrgAccess(atts.getValue("isUseUserOrgAccess") != null ? Boolean + .valueOf(atts.getValue("isUseUserOrgAccess")) + .booleanValue() + : true); + m_Role + .setOverwritePriceLimit(atts.getValue("isOverwritePriceLimit") != null ? Boolean + .valueOf(atts.getValue("isOverwritePriceLimit")) + .booleanValue() + : true); + m_Role.setPreferenceType(atts.getValue("PreferenceType")); + m_Role.setUserLevel(atts.getValue("UserLevel")); + + if (m_Role.save(getTrxName(ctx)) == true) { + + record_log(ctx, 1, m_Role.getName(), "Role", m_Role.get_ID(), + AD_Backup_ID, Object_Status, "AD_Role", get_IDWithColumn( + ctx, "AD_Table", "TableName", "AD_Role")); + } else { + + record_log(ctx, 0, m_Role.getName(), "Role", m_Role.get_ID(), + AD_Backup_ID, Object_Status, "AD_Role", get_IDWithColumn( + ctx, "AD_Table", "TableName", "AD_Role")); + throw new POSaveFailedException("Role"); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int Role_id = Env.getContextAsInt(ctx, + X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID); + X_AD_Role m_Role = new X_AD_Role(ctx, Role_id, null); + AttributesImpl atts = new AttributesImpl(); + createRoleBinding(atts, m_Role); + document.startElement("", "", "role", atts); + + // Process org access + String sql = "SELECT * FROM AD_Role_OrgAccess WHERE AD_Role_ID= " + + Role_id; + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + createOrgAccess(ctx, document, rs.getInt("AD_Org_ID"), rs + .getInt("AD_Role_ID")); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e) { + log.log(Level.SEVERE, "AD_Role_OrgAccess", e); + throw new DatabaseAccessException("AD_Role_OrgAccess"); + } + // Process user assignment access + sql = "SELECT * FROM AD_User_Roles WHERE AD_Role_ID= " + Role_id; + pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + createUserRole(ctx, document, rs.getInt("AD_User_ID"), + rs.getInt("AD_Role_ID"), rs.getInt("AD_Org_ID")); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e) { + log.log(Level.SEVERE, "AD_User_Roles", e); + throw new DatabaseAccessException("AD_User_Roles"); + } + + // Process AD_Window_Access Values + sql = "SELECT * FROM AD_Window_Access WHERE AD_Role_ID= " + Role_id; + pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + createWindowAccess(ctx, document, rs + .getInt("AD_Window_ID"), rs.getInt("AD_Role_ID")); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e) { + log.log(Level.SEVERE, "AD_Window_Access", e); + throw new DatabaseAccessException("AD_Window_Access"); + } + + // Process AD_Process_Access Values + sql = "SELECT * FROM AD_Process_Access WHERE AD_Role_ID= " + Role_id; + pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + createProcessAccess(ctx, document, rs + .getInt("AD_Process_ID"), rs.getInt("AD_Role_ID")); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e) { + log.log(Level.SEVERE, "AD_Process_Access", e); + throw new DatabaseAccessException("AD_Process_Access"); + } + + // Process AD_Form_Access Values + sql = "SELECT * FROM AD_Form_Access WHERE AD_Role_ID= " + Role_id; + pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + createFormAccess(ctx, document, rs.getInt("AD_Form_ID"), + rs.getInt("AD_Role_ID")); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e) { + log.log(Level.SEVERE, "AD_Form_Access", e); + throw new DatabaseAccessException("AD_Form_Access"); + } + + // Process AD_Workflow_Access Values + sql = "SELECT * FROM AD_Workflow_Access WHERE AD_Role_ID= " + Role_id; + pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + createWorkflowAccess(ctx, document, rs + .getInt("AD_Workflow_ID"), rs.getInt("AD_Role_ID")); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e) { + log.log(Level.SEVERE, "AD_Workflow_Access", e); + throw new DatabaseAccessException("AD_Workflow_Access"); + } + + // Process AD_Task_Access Values + sql = "SELECT * FROM AD_Task_Access WHERE AD_Role_ID= " + Role_id; + pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + createTaskAccess(ctx, document, rs.getInt("AD_Task_ID"), rs + .getInt("AD_Role_ID")); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e) { + log.log(Level.SEVERE, "AD_Task_Access", e); + throw new DatabaseAccessException("AD_Task_Access"); + } finally { + try { + if (pstmt != null) + pstmt.close(); + } catch (Exception e) { + } + pstmt = null; + } + document.endElement("", "", "role"); + } + + private void createTaskAccess(Properties ctx, TransformerHandler document, + int AD_Task_ID, int AD_Role_ID) throws SAXException { + Env.setContext(ctx, X_AD_Task.COLUMNNAME_AD_Task_ID, AD_Task_ID); + Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + taskHandler.create(ctx, document); + ctx.remove(X_AD_Task.COLUMNNAME_AD_Task_ID); + ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + } + + private void createWorkflowAccess(Properties ctx, + TransformerHandler document, int AD_Workflow_ID, int AD_Role_ID) throws SAXException { + Env.setContext(ctx, X_AD_Workflow.COLUMNNAME_AD_Workflow_ID, AD_Workflow_ID); + Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + workflowHandler.create(ctx, document); + ctx.remove(X_AD_Workflow.COLUMNNAME_AD_Workflow_ID); + ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + } + + private void createFormAccess(Properties ctx, TransformerHandler document, + int AD_Form_ID, int AD_Role_ID) throws SAXException { + Env.setContext(ctx, X_AD_Form.COLUMNNAME_AD_Form_ID, AD_Form_ID); + Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + formHandler.create(ctx, document); + ctx.remove(X_AD_Form.COLUMNNAME_AD_Form_ID); + ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + } + + private void createProcessAccess(Properties ctx, + TransformerHandler document, int AD_Process_ID, int AD_Role_ID) throws SAXException { + Env.setContext(ctx, X_AD_Process.COLUMNNAME_AD_Process_ID, AD_Process_ID); + Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + processHandler.create(ctx, document); + ctx.remove(X_AD_Process.COLUMNNAME_AD_Process_ID); + ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + } + + private void createWindowAccess(Properties ctx, + TransformerHandler document, int AD_Window_ID, int AD_Role_ID) throws SAXException { + Env.setContext(ctx, X_AD_Window.COLUMNNAME_AD_Window_ID, AD_Window_ID); + Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + windowHandler.create(ctx, document); + ctx.remove(X_AD_Window.COLUMNNAME_AD_Window_ID); + ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + } + + private void createUserRole(Properties ctx, TransformerHandler document, + int AD_User_ID, int AD_Role_ID, int AD_Org_ID) throws SAXException { + Env.setContext(ctx, X_AD_User.COLUMNNAME_AD_User_ID, AD_User_ID); + Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + Env.setContext(ctx, "AD_Org_ID", AD_Org_ID); + userHandler.create(ctx, document); + ctx.remove(X_AD_User.COLUMNNAME_AD_User_ID); + ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + ctx.remove("AD_Org_ID"); + } + + private void createOrgAccess(Properties ctx, TransformerHandler document, + int AD_Org_ID, int AD_Role_ID) throws SAXException { + Env.setContext(ctx, "AD_Org_ID", AD_Org_ID); + Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + orgHandler.create(ctx, document); + ctx.remove("AD_Org_ID"); + ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + } + + private AttributesImpl createRoleBinding(AttributesImpl atts, + X_AD_Role m_Role) { + String sql = null; + String name = null; + atts.clear(); + + if (m_Role.getAD_Tree_Menu_ID() > 0) { + sql = "SELECT Name FROM AD_Tree WHERE AD_Tree_ID=? AND AD_Tree.TreeType='MM'"; + name = DB.getSQLValueString(null, sql, m_Role.getAD_Tree_Menu_ID()); + atts.addAttribute("", "", "treemenuname", "CDATA", name); + } else + atts.addAttribute("", "", "treemenuname", "CDATA", ""); + + if (m_Role.getAD_Tree_Org_ID() > 0) { + sql = "SELECT Name FROM AD_Tree WHERE AD_Tree_ID=? AND AD_Tree.TreeType='OO'"; + name = DB.getSQLValueString(null, sql, m_Role.getAD_Tree_Org_ID()); + atts.addAttribute("", "", "treeorgname", "CDATA", name); + } else + atts.addAttribute("", "", "treeorgname", "CDATA", ""); + + if (m_Role.getC_Currency_ID() > 0) { + sql = "SELECT ISO_Code FROM C_Currency WHERE C_Currency_ID=?"; + name = DB.getSQLValueString(null, sql, m_Role.getC_Currency_ID()); + atts.addAttribute("", "", "currencycode", "CDATA", name); + } else + atts.addAttribute("", "", "currencycode", "CDATA", ""); + + if (m_Role.getSupervisor_ID() > 0) { + sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?"; + name = DB.getSQLValueString(null, sql, m_Role.getC_Currency_ID()); + atts.addAttribute("", "", "supervisorid", "CDATA", name); + } else + atts.addAttribute("", "", "supervisorid", "CDATA", ""); + + atts.addAttribute("", "", "Description", "CDATA", (m_Role + .getDescription() != null ? m_Role.getDescription() : "")); + atts.addAttribute("", "", "Name", "CDATA", + (m_Role.getName() != null ? m_Role.getName() : "")); + atts.addAttribute("", "", "AmtApproval", "CDATA", ("" + m_Role + .getAmtApproval())); + atts.addAttribute("", "", "isAccessAllOrgs", "CDATA", (m_Role + .isAccessAllOrgs() == true ? "true" : "false")); + atts.addAttribute("", "", "isActive", "CDATA", + (m_Role.isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "isCanApproveOwnDoc", "CDATA", (m_Role + .isCanApproveOwnDoc() == true ? "true" : "false")); + atts.addAttribute("", "", "isCanExport", "CDATA", + (m_Role.isCanExport() == true ? "true" : "false")); + atts.addAttribute("", "", "isCanReport", "CDATA", + (m_Role.isCanReport() == true ? "true" : "false")); + atts.addAttribute("", "", "isChangeLog", "CDATA", + (m_Role.isChangeLog() == true ? "true" : "false")); + atts.addAttribute("", "", "isManual", "CDATA", + (m_Role.isManual() == true ? "true" : "false")); + atts.addAttribute("", "", "isPersonalAccess", "CDATA", (m_Role + .isPersonalAccess() == true ? "true" : "false")); + atts.addAttribute("", "", "isPersonalLock", "CDATA", (m_Role + .isPersonalLock() == true ? "true" : "false")); + atts.addAttribute("", "", "isShowAcct", "CDATA", + (m_Role.isShowAcct() == true ? "true" : "false")); + atts.addAttribute("", "", "isUseUserOrgAccess", "CDATA", (m_Role + .isUseUserOrgAccess() == true ? "true" : "false")); + atts.addAttribute("", "", "isOverwritePriceLimit", "CDATA", (m_Role + .isOverwritePriceLimit() == true ? "true" : "false")); + atts + .addAttribute("", "", "PreferenceType", "CDATA", (m_Role + .getPreferenceType() != null ? m_Role + .getPreferenceType() : "")); + atts.addAttribute("", "", "UserLevel", "CDATA", + (m_Role.getUserLevel() != null ? m_Role.getUserLevel() : "")); + + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/SQLStatementElementHandler.java b/base/src/org/adempiere/pipo/handler/SQLStatementElementHandler.java new file mode 100644 index 0000000000..ce41a34cdf --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/SQLStatementElementHandler.java @@ -0,0 +1,101 @@ +/****************************************************************************** + * 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.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.Statement; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.compiere.model.X_AD_Package_Exp_Detail; +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 SQLStatementElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + + log.info(elementValue); + Attributes atts = element.attributes; + String DBType = atts.getValue("DBType"); + PreparedStatement pstmt = DB.prepareStatement(atts.getValue("statement"), getTrxName(ctx)); + try { + if(DBType.equals("ALL")) { + int n = pstmt.executeUpdate(); + log.info("Executed SQL Statement: "+ atts.getValue("statement")); + } + else if(DB.isOracle() == true && DBType.equals("Oracle")) { + pstmt.executeUpdate(); + log.info("Executed SQL Statement for Oracle: "+ atts.getValue("statement")); + } + else if(DB.isPostgreSQL() == true && DBType.equals("PostgreSQL")){ + // Avoid convert layer - command specific for postgresql + // + // pstmt = DB.prepareStatement(sql, null); + // pstmt.executeUpdate(); + // + Connection m_con = DB.getConnectionRW(true); + Statement stmt = m_con.createStatement(); + int n = stmt.executeUpdate (atts.getValue("statement")); + log.info("Executed SQL Statement for PostgreSQL: "+ atts.getValue("statement")); + // Postgres needs to commit DDL statements + if (m_con != null && !m_con.getAutoCommit()) + m_con.commit(); + } + /* else if(DB.isSybase() == true && DBType.equals("Sybase")){ + pstmt.executeUpdate(); + log.info("Exceuted SQL Statement for Sybase"); + } + */ } + catch (Exception e) { + log.log(Level.SEVERE,"SQLSatement", e); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + String SQLStatement = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); + String DBType = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_DBType); + AttributesImpl atts = new AttributesImpl(); + createSQLStatmentBinding(atts, SQLStatement, DBType); + document.startElement("","","SQLStatement",atts); + document.endElement("","","SQLStatement"); + } + + private AttributesImpl createSQLStatmentBinding( AttributesImpl atts, String SqlStatement, String DBType) + { + atts.clear(); + atts.addAttribute("","","DBType","CDATA",DBType); + atts.addAttribute("","","statement","CDATA",SqlStatement); + return atts; + + } +} diff --git a/base/src/org/adempiere/pipo/handler/TabElementHandler.java b/base/src/org/adempiere/pipo/handler/TabElementHandler.java new file mode 100644 index 0000000000..6c2e4e724c --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/TabElementHandler.java @@ -0,0 +1,296 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.PackOut; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.compiere.model.MTab; +import org.compiere.model.X_AD_Field; +import org.compiere.model.X_AD_Tab; +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 TabElementHandler extends AbstractElementHandler { + + private FieldElementHandler fieldHandler = new FieldElementHandler(); + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + log.info(elementValue+" "+atts.getValue("ADTabNameID")); + String entitytype = atts.getValue("EntityType"); + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && getUpdateMode(ctx).compareTo("true") == 0) { + + String name = atts.getValue("ADTabNameID"); + int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID")); + int windowid = get_ID(ctx, "AD_Window", atts.getValue("ADWindowNameID")); + StringBuffer sqlB = new StringBuffer ("select AD_Tab_ID from AD_Tab where AD_Window_ID = " + windowid + + " and Name = '"+name +"'" + + " and AD_Table_ID = ?"); + + int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString (), tableid); + MTab m_Tab = new MTab(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0){ + AD_Backup_ID = copyRecord(ctx, "AD_Tab",m_Tab); + Object_Status = "Update"; + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + } + sqlB = null; + m_Tab.setName(name); + id = 0; + if (atts.getValue("ADColumnSortYesNoNameID")!= null){ + name = atts.getValue("ADColumnSortYesNoNameID"); + id = get_IDWithColumn(ctx, "AD_Column", "Name", name); + m_Tab.setAD_ColumnSortYesNo_ID(id); + } + if (atts.getValue("ADColumnSortOrderNameID")!= null){ + name = atts.getValue("ADColumnSortOrderNameID"); + id = get_IDWithColumn(ctx, "AD_Column", "Name", name); + m_Tab.setAD_ColumnSortOrder_ID(id); + } + if (atts.getValue("ADImageNameID")!= null){ + name = atts.getValue("ADImageNameID"); + id = get_IDWithColumn(ctx, "AD_Image", "Name", name); + m_Tab.setAD_Image_ID(id); + } + if (atts.getValue("ADProcessNameID")!= null){ + name = atts.getValue("ADProcessNameID"); + id = get_IDWithColumn(ctx, "AD_Process", "Name", name); + m_Tab.setAD_Process_ID(id); + } + if (atts.getValue("ADTableNameID")!= null){ + name = atts.getValue("ADTableNameID"); + id = get_IDWithColumn(ctx, "AD_Table", "TableName", name); + m_Tab.setAD_Table_ID(id); + } + if (atts.getValue("ADColumnNameID")!= null){ + name = atts.getValue("ADColumnNameID"); + id = get_IDWithMasterAndColumn (ctx, "AD_Column","Name", atts.getValue("ADColumnNameID"), "AD_Table", get_IDWithColumn(ctx,"AD_Table", "TableName", atts.getValue("ADTableNameID"))); + m_Tab.setAD_Column_ID(id); + } + if (atts.getValue("ADWindowNameID")!= null){ + name = atts.getValue("ADWindowNameID"); + id = get_IDWithColumn(ctx, "AD_Window", "Name", name); + m_Tab.setAD_Window_ID(id); + } + if (atts.getValue("IncludedTabNameID")!= null){ + name = atts.getValue("IncludedTabNameID"); + id = get_IDWithColumn(ctx, "AD_Tab", "Name", name); + m_Tab.setIncluded_Tab_ID(id); + } + m_Tab.setCommitWarning(atts.getValue("CommitWarning")); + m_Tab.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); + m_Tab.setEntityType (atts.getValue("EntityType")); + m_Tab.setHasTree(Boolean.valueOf(atts.getValue("isHasTree")).booleanValue()); + m_Tab.setHelp (atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); + m_Tab.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); + m_Tab.setImportFields (atts.getValue("ImportFields")); + m_Tab.setIsInfoTab (Boolean.valueOf(atts.getValue("isInfoTab")).booleanValue()); + m_Tab.setIsReadOnly (Boolean.valueOf(atts.getValue("isReadOnly")).booleanValue()); + m_Tab.setIsSingleRow (Boolean.valueOf(atts.getValue("isSingleRow")).booleanValue()); + m_Tab.setIsSortTab (Boolean.valueOf(atts.getValue("isSortTab")).booleanValue()); + m_Tab.setIsTranslationTab (Boolean.valueOf(atts.getValue("IsTranslationTab")).booleanValue()); + m_Tab.setName (atts.getValue("Name")); + m_Tab.setOrderByClause (atts.getValue("OrderByClause")); + m_Tab.setProcessing(false); + m_Tab.setSeqNo (Integer.parseInt(atts.getValue("SeqNo"))); + m_Tab.setTabLevel (Integer.parseInt(atts.getValue("TabLevel"))); + m_Tab.setWhereClause (atts.getValue("WhereClause")); + if (atts.getValue("ReadOnlyLogic") != null) { + m_Tab.setReadOnlyLogic(atts.getValue("ReadOnlyLogic")); + } + if (atts.getValue("DisplayLogic") != null) { + m_Tab.setDisplayLogic(atts.getValue("DisplayLogic")); + } + if (atts.getValue("isInsertRecord") != null) { + m_Tab.setIsInsertRecord(Boolean.valueOf(atts.getValue("isInsertRecord")).booleanValue()); + } + if (atts.getValue("isAdvancedTab") != null) { + m_Tab.setIsAdvancedTab(Boolean.valueOf(atts.getValue("isAdvancedTab")).booleanValue()); + } + if (m_Tab.save(getTrxName(ctx)) == true){ + record_log (ctx, 1, m_Tab.getName(),"Tab", m_Tab.get_ID(),AD_Backup_ID, Object_Status,"AD_Tab",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Tab")); + } else { + record_log (ctx, 0, m_Tab.getName(),"Tab", m_Tab.get_ID(),AD_Backup_ID, Object_Status,"AD_Tab",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Tab")); + } + + } + + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + PackOut packOut = (PackOut)ctx.get("PackOutProcess"); + int AD_Tab_ID = Env.getContextAsInt(ctx, X_AD_Tab.COLUMNNAME_AD_Tab_ID); + X_AD_Tab m_Tab = new X_AD_Tab (ctx, AD_Tab_ID, getTrxName(ctx)); + AttributesImpl atts = new AttributesImpl(); + createTabBinding(atts,m_Tab); + document.startElement("","","tab",atts); + //Fields tags. + String sql = "SELECT * FROM AD_FIELD WHERE AD_TAB_ID = " + AD_Tab_ID + + "ORDER BY SEQNO asc"; + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement (sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) + { + createField(ctx, document, rs.getInt("AD_Field_ID")); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + catch (Exception e) + { + log.log(Level.SEVERE,e.getLocalizedMessage(), e); + throw new DatabaseAccessException("Tab", e); + } + finally + { + try + { + if (pstmt != null) + pstmt.close (); + } + catch (Exception e) + {} + pstmt = null; + } + document.endElement("","","tab"); + + if(m_Tab.getAD_Process_ID() > 0 ) + { + packOut.createProcess(m_Tab.getAD_Process_ID(), atts, document); + } + + } + + private void createField(Properties ctx, TransformerHandler document, + int AD_Field_ID) throws SAXException { + Env.setContext(ctx, X_AD_Field.COLUMNNAME_AD_Field_ID, AD_Field_ID); + fieldHandler.create(ctx, document); + ctx.remove(X_AD_Field.COLUMNNAME_AD_Field_ID); + } + + private AttributesImpl createTabBinding( AttributesImpl atts, X_AD_Tab m_Tab) + { + String sql = null; + String name = null; + atts.clear(); + atts.addAttribute("","","Name","CDATA",(m_Tab.getName () != null ? m_Tab.getName ():"")); + if (m_Tab.getAD_ColumnSortOrder_ID()>0){ + sql = "SELECT Name FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null,sql,m_Tab.getAD_ColumnSortOrder_ID()); + atts.addAttribute("","","ADColumnSortOrderNameID","CDATA",name); + } + else + atts.addAttribute("","","ADColumnSortOrderNameID","CDATA",""); + if (m_Tab.getAD_ColumnSortYesNo_ID()>0 ){ + sql = "SELECT Name FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null,sql,m_Tab.getAD_ColumnSortYesNo_ID()); + atts.addAttribute("","","ADColumnSortYesNoNameID","CDATA",name); + } + else + atts.addAttribute("","","ADColumnSortYesNoNameID","CDATA",""); + if (m_Tab.getAD_Column_ID()>0 ){ + sql = "SELECT Name FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null,sql,m_Tab.getAD_Column_ID()); + atts.addAttribute("","","ADColumnNameID","CDATA",name); + } + else + atts.addAttribute("","","ADColumnNameID","CDATA",""); + if (m_Tab.getAD_Image_ID() >0 ){ + sql = "SELECT Name FROM AD_Image WHERE AD_Image_ID=?"; + name = DB.getSQLValueString(null,sql,m_Tab.getAD_Image_ID()); + atts.addAttribute("","","ADImageNameID","CDATA",name); + } + else + atts.addAttribute("","","ADImageNameID","CDATA",""); + if (m_Tab.getAD_Process_ID() >0 ){ + sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; + name = DB.getSQLValueString(null,sql,m_Tab.getAD_Process_ID()); + atts.addAttribute("","","ADProcessNameID","CDATA",name); + } + else + atts.addAttribute("","","ADProcessNameID","CDATA",""); + if (m_Tab.getAD_Tab_ID() >0 ){ + sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?"; + name = DB.getSQLValueString(null,sql,m_Tab.getAD_Tab_ID()); + atts.addAttribute("","","ADTabNameID","CDATA",name); + } + else + atts.addAttribute("","","ADTabNameID","CDATA",""); + + sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; + name = DB.getSQLValueString(null,sql,m_Tab.getAD_Table_ID()); + atts.addAttribute("","","ADTableNameID","CDATA",name); + sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; + name = DB.getSQLValueString(null,sql,m_Tab.getAD_Window_ID()); + atts.addAttribute("","","ADWindowNameID","CDATA",name); + if (m_Tab.getIncluded_Tab_ID() > 0 ){ + sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?"; + name = DB.getSQLValueString(null,sql,m_Tab.getIncluded_Tab_ID()); + atts.addAttribute("","","IncludedTabNameID","CDATA",name); + } + else + atts.addAttribute("","","IncludedTabNameID","CDATA",""); + atts.addAttribute("","","CommitWarning","CDATA",(m_Tab.getCommitWarning () != null ? m_Tab.getCommitWarning ():"")); + atts.addAttribute("","","Description","CDATA",(m_Tab.getDescription () != null ? m_Tab.getDescription ():"")); + atts.addAttribute("","","EntityType","CDATA",(m_Tab.getEntityType () != null ? m_Tab.getEntityType ():"")); + atts.addAttribute("","","isHasTree","CDATA",(m_Tab.isHasTree()== true ? "true":"false")); + atts.addAttribute("","","Help","CDATA",(m_Tab.getHelp () != null ? m_Tab.getHelp ():"")); + atts.addAttribute("","","isInfoTab","CDATA",(m_Tab.isInfoTab()== true ? "true":"false")); + atts.addAttribute("","","isReadOnly","CDATA",(m_Tab.isReadOnly()== true ? "true":"false")); + atts.addAttribute("","","isSingleRow","CDATA",(m_Tab.isSingleRow()== true ? "true":"false")); + atts.addAttribute("","","isSortTab","CDATA",(m_Tab.isSortTab()== true ? "true":"false")); + atts.addAttribute("","","isActive","CDATA",(m_Tab.isActive()== true ? "true":"false")); + atts.addAttribute("","","IsTranslationTab","CDATA",(m_Tab.isTranslationTab()== true ? "true":"false")); + atts.addAttribute("","","OrderByClause","CDATA",(m_Tab.getOrderByClause () != null ? m_Tab.getOrderByClause ():"")); + atts.addAttribute("","","isProcessing","CDATA",(m_Tab.isProcessing()== true ? "true":"false")); + atts.addAttribute("","","SeqNo","CDATA",(m_Tab.getSeqNo () >= 0 ? "" + m_Tab.getSeqNo ():"0")); + atts.addAttribute("","","TabLevel","CDATA",(m_Tab.getTabLevel () >= 0 ? "" + m_Tab.getTabLevel ():"")); + atts.addAttribute("","","WhereClause","CDATA",(m_Tab.getWhereClause () != null ? m_Tab.getWhereClause ():"")); + atts.addAttribute("","","ReadOnlyLogic","CDATA",(m_Tab.getReadOnlyLogic() != null ? m_Tab.getReadOnlyLogic ():"")); + atts.addAttribute("","","DisplayLogic","CDATA",(m_Tab.getDisplayLogic() != null ? m_Tab.getDisplayLogic ():"")); + atts.addAttribute("","","isInsertRecord","CDATA",(m_Tab.isInsertRecord()== true ? "true":"false")); + atts.addAttribute("","","isAdvancedTab","CDATA",(m_Tab.isAdvancedTab()== true ? "true":"false")); + atts.addAttribute("","","Syncfields","CDATA","false"); + return atts; + } + +} diff --git a/base/src/org/adempiere/pipo/handler/TableElementHandler.java b/base/src/org/adempiere/pipo/handler/TableElementHandler.java new file mode 100644 index 0000000000..b72e24bf97 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/TableElementHandler.java @@ -0,0 +1,271 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.PackOut; +import org.compiere.model.MTable; +import org.compiere.model.X_AD_Column; +import org.compiere.model.X_AD_Package_Exp_Detail; +import org.compiere.model.X_AD_Table; +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 TableElementHandler extends AbstractElementHandler { + private ColumnElementHandler columnHandler = new ColumnElementHandler(); + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + log.info(elementValue+" "+atts.getValue("ADTableNameID")); + String entitytype = atts.getValue("EntityType"); + + if (entitytype.equals("U") || entitytype.equals("D") && getUpdateMode(ctx).equals("true")) { + + String tableName = atts.getValue("ADTableNameID"); + + int id = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName); + + MTable m_Table = new MTable(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0){ + AD_Backup_ID = copyRecord(ctx, "AD_Table",m_Table); + Object_Status = "Update"; + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + } + m_Table.setTableName(tableName); + String Name = atts.getValue("ADWindowNameID"); + id = get_IDWithColumn(ctx, "AD_Window", "Name", Name); + m_Table.setAD_Window_ID(id); + Name = atts.getValue("POWindowNameID"); + if (Name != null){ + id = get_IDWithColumn(ctx, "AD_Window", "Name", Name); + m_Table.setPO_Window_ID(id); + } + else + Name = atts.getValue("ADValRuleNameID"); + id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name); + + m_Table.setAD_Val_Rule_ID(id); + m_Table.setAccessLevel (atts.getValue("AccessLevel")); + m_Table.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); + m_Table.setEntityType(atts.getValue("EntityType")); + m_Table.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); + m_Table.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); + m_Table.setImportTable(atts.getValue("ImportTable")); + m_Table.setIsChangeLog(Boolean.valueOf(atts.getValue("isChangeLog")).booleanValue()); + m_Table.setIsDeleteable(Boolean.valueOf(atts.getValue("isDeleteable")).booleanValue()); + m_Table.setIsHighVolume(Boolean.valueOf(atts.getValue("isHighVolume")).booleanValue()); + m_Table.setIsSecurityEnabled(Boolean.valueOf(atts.getValue("isSecurityEnabled")).booleanValue()); + m_Table.setIsView(Boolean.valueOf(atts.getValue("isView")).booleanValue()); + //m_Table.setLoadSeq(Integer.parseInt(atts.getValue("LoadSeq"))); + m_Table.setName(atts.getValue("Name")); + m_Table.setReplicationType(atts.getValue("ReplicationType")); + m_Table.setTableName(atts.getValue("TableName")); +// log.info("in3"); + getDocumentAttributes(ctx).clear(); + if (m_Table.save(getTrxName(ctx)) == true){ + record_log (ctx, 1, m_Table.getName(),"Table", m_Table.get_ID(),AD_Backup_ID, Object_Status,"AD_Table",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table")); + } + else{ + record_log (ctx, 0, m_Table.getName(),"Table", m_Table.get_ID(),AD_Backup_ID, Object_Status,"AD_Table",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table")); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + + int AD_Table_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID); + PackOut packOut = (PackOut)ctx.get("PackOutProcess"); + boolean exported = isTableExported(ctx, AD_Table_ID); + AttributesImpl atts = new AttributesImpl(); + //Export table if not already done so + if (!exported){ + + String sql = "SELECT Name FROM AD_Table WHERE AD_Table_ID= " + AD_Table_ID; + + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement (sql, getTrxName(ctx)); + + try { + + ResultSet rs = pstmt.executeQuery(); + + while (rs.next()) + { + X_AD_Table m_Table = new X_AD_Table (ctx, AD_Table_ID, null); + createTableBinding(atts,m_Table); + document.startElement("","","table",atts); + + String sql1 = "SELECT * FROM AD_Column WHERE AD_Table_ID = " + AD_Table_ID + + " ORDER BY SEQNO asc"; + + PreparedStatement pstmt1 = null; + pstmt1 = DB.prepareStatement (sql1, getTrxName(ctx)); + + try { + + ResultSet rs1 = pstmt1.executeQuery(); + + while (rs1.next()){ + + if (rs1.getInt("AD_Reference_ID")>0) + packOut.createReference (rs1.getInt("AD_Reference_ID"), atts, document); + + if (rs1.getInt("AD_Reference_Value_ID")>0) + packOut.createReference (rs1.getInt("AD_Reference_Value_ID"), atts, document); + + if (rs1.getInt("AD_Process_ID")>0) + packOut.createProcess (rs1.getInt("AD_Process_ID"), atts, document); + + if (rs1.getInt("AD_Val_Rule_ID")>0) + packOut.createDynamicRuleValidation (rs1.getInt("AD_Val_Rule_ID"), atts, document); + + createColumn(ctx, document, rs1.getInt("AD_Column_ID")); + } + + rs1.close(); + pstmt1.close(); + pstmt1 = null; + } + catch (Exception e) { + log.log(Level.SEVERE,"getProcess", e); + } + finally { + try { + if (pstmt1 != null) + pstmt1.close (); + } + catch (Exception e){} + pstmt1 = null; + } + document.endElement("","","table"); + } + rs.close(); + pstmt.close(); + pstmt = null; + } + + catch (Exception e){ + log.log(Level.SEVERE,"getProcess", e); + } + finally{ + try { + if (pstmt != null) + pstmt.close (); + } + catch (Exception e){} + pstmt = null; + } + } + + } + + private void createColumn(Properties ctx, TransformerHandler document, int AD_Column_ID) throws SAXException { + Env.setContext(ctx, X_AD_Column.COLUMNNAME_AD_Column_ID, AD_Column_ID); + columnHandler.create(ctx, document); + ctx.remove(X_AD_Column.COLUMNNAME_AD_Column_ID); + } + + private boolean isTableExported(Properties ctx, int AD_Table_ID) { + Listtables = (List)ctx.get("ExportedTables"); + if (tables == null) { + tables = new ArrayList(); + tables.add(AD_Table_ID); + return false; + } else { + if (tables.contains(AD_Table_ID)) + return true; + else { + tables.add(AD_Table_ID); + return false; + } + } + } + + private AttributesImpl createTableBinding( AttributesImpl atts, X_AD_Table m_Table) + { + String sql = null; + String name = null; + atts.clear(); + atts.addAttribute("","","Name","CDATA",(m_Table.getName () != null ? m_Table.getName ():"")); + if (m_Table.getAD_Table_ID()> 0 ){ + sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; + name = DB.getSQLValueString(null,sql,m_Table.getAD_Table_ID()); + atts.addAttribute("","","ADTableNameID","CDATA",name); + } + else + atts.addAttribute("","","ADTableNameID","CDATA",""); + if (m_Table.getAD_Window_ID()> 0 ){ + sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; + name = DB.getSQLValueString(null,sql,m_Table.getAD_Window_ID()); + atts.addAttribute("","","ADWindowNameID","CDATA",name); + } + else + atts.addAttribute("","","ADWindowNameID","CDATA",""); + if (m_Table.getPO_Window_ID()> 0 ){ + sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; + name = DB.getSQLValueString(null,sql,m_Table.getPO_Window_ID()); + atts.addAttribute("","","POWindowNameID","CDATA",name); + } + else + atts.addAttribute("","","POWindowNameID","CDATA",""); + if (m_Table.getAD_Val_Rule_ID()> 0 ){ + sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?"; + name = DB.getSQLValueString(null,sql,m_Table.getAD_Val_Rule_ID()); + atts.addAttribute("","","ADValRuleNameID","CDATA",name); + } + else + atts.addAttribute("","","ADValRuleNameID","CDATA",""); + atts.addAttribute("","","AccessLevel","CDATA",(m_Table.getAccessLevel () != null ? m_Table.getAccessLevel ():"")); + atts.addAttribute("","","Description","CDATA",(m_Table.getDescription () != null ? m_Table.getDescription ():"")); + atts.addAttribute("","","EntityType","CDATA",(m_Table.getEntityType () != null ? m_Table.getEntityType ():"")); + atts.addAttribute("","","Help","CDATA",(m_Table.getHelp() != null ? m_Table.getHelp ():"")); + atts.addAttribute("","","ImportTable","CDATA",(m_Table.getImportTable () != null ? m_Table.getImportTable ():"")); + atts.addAttribute("","","isChangeLog","CDATA",(m_Table.isChangeLog()== true ? "true":"false")); + atts.addAttribute("","","isActive","CDATA",(m_Table.isActive()== true ? "true":"false")); + atts.addAttribute("","","isDeleteable","CDATA",(m_Table.isDeleteable()== true ? "true":"false")); + atts.addAttribute("","","isHighVolume","CDATA",(m_Table.isHighVolume()== true ? "true":"false")); + atts.addAttribute("","","isSecurityEnabled","CDATA",(m_Table.isSecurityEnabled()== true ? "true":"false")); + atts.addAttribute("","","isView","CDATA",(m_Table.isView()== true ? "true":"false")); + atts.addAttribute("","","LoadSeq","CDATA",(m_Table.getLoadSeq ()> 0 ? "" + m_Table.getLoadSeq ():"")); + atts.addAttribute("","","ReplicationType","CDATA",(m_Table.getReplicationType () != null ? m_Table.getReplicationType ():"")); + atts.addAttribute("","","TableName","CDATA",(m_Table.getTableName () != null ? m_Table.getTableName ():"")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/TaskAccessElementHandler.java b/base/src/org/adempiere/pipo/handler/TaskAccessElementHandler.java new file mode 100644 index 0000000000..08bca89058 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/TaskAccessElementHandler.java @@ -0,0 +1,135 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.compiere.model.X_AD_Role; +import org.compiere.model.X_AD_Task; +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 TaskAccessElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + log.info(elementValue); + int roleid =0; + int taskid =0; + StringBuffer sqlB = null; + Attributes atts = element.attributes; + if (atts.getValue("rolename")!=null){ + String name = atts.getValue("rolename"); + sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); + roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + if (atts.getValue("taskname")!=null){ + String name = atts.getValue("taskname"); + sqlB = new StringBuffer ("SELECT AD_Task_ID FROM AD_Task WHERE Name= ?"); + taskid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + sqlB = new StringBuffer ("SELECT count(*) FROM AD_Task_Access WHERE AD_Role_ID=? and AD_Task_ID=?"); + int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,taskid); + int AD_Backup_ID = -1; + String Object_Status = null; + if (count>0){ + Object_Status = "Update"; + sqlB = new StringBuffer ("UPDATE AD_Task_Access ") + .append( "SET isActive = '" + atts.getValue("isActive") ) + .append( "', isReadWrite = '" + atts.getValue("isReadWrite") ) + .append( "' WHERE AD_Role_ID = " + roleid ) + .append( " and AD_Task_ID = " + taskid ); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) { + log.info("Update to task access failed"); + throw new DatabaseAccessException("Update to task access failed"); + } + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + sqlB = new StringBuffer ("Insert INTO AD_Task_Access") + .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_Role_ID, AD_Task_ID, isActive, isReadWrite) " ) + .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( ", " + roleid ) + .append( ", " + taskid ) + .append( ", '" + atts.getValue("isActive") ) + .append( "', '" + atts.getValue("isReadWrite")+"')" ); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) { + log.info("Insert to task access failed"); + throw new DatabaseAccessException("Insert to task access failed"); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Task_ID = Env.getContextAsInt(ctx, X_AD_Task.COLUMNNAME_AD_Task_ID); + int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + AttributesImpl atts = new AttributesImpl(); + createTaskAccessBinding(atts, AD_Task_ID, AD_Role_ID); + document.startElement("", "", "taskaccess", atts); + document.endElement("", "", "taskaccess"); + } + + private AttributesImpl createTaskAccessBinding(AttributesImpl atts, + int task_id, int role_id) { + String sql = null; + String name = null; + atts.clear(); + + sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?"; + name = DB.getSQLValueString(null, sql, task_id); + atts.addAttribute("", "", "taskname", "CDATA", name); + + sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; + name = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "rolename", "CDATA", name); + + sql = "SELECT isActive FROM AD_Task_Access WHERE AD_Task_ID=" + task_id + + " and AD_Role_ID=?"; + String TrueFalse = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isActive", "CDATA", TrueFalse); + + sql = "SELECT isReadWrite FROM AD_Task_Access WHERE AD_Task_ID=" + + task_id + " and AD_Role_ID=?"; + String isReadWrite = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isReadWrite", "CDATA", isReadWrite); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/TaskElementHandler.java b/base/src/org/adempiere/pipo/handler/TaskElementHandler.java new file mode 100644 index 0000000000..9e4bcbd27e --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/TaskElementHandler.java @@ -0,0 +1,107 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.compiere.model.MTask; +import org.compiere.model.X_AD_Task; +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 TaskElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + log.info(elementValue+" "+atts.getValue("ADTaskNameID")); + String entitytype = atts.getValue("EntityType"); + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && getUpdateMode(ctx).compareTo("true") == 0 ) { + String name = atts.getValue("ADTaskNameID"); + int id = get_ID(ctx, "AD_Task", name); + MTask m_Task = new MTask(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0){ + AD_Backup_ID = copyRecord(ctx, "AD_Task",m_Task); + Object_Status = "Update"; + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + } + m_Task.setAccessLevel(atts.getValue("AccessLevel")); + m_Task.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); + m_Task.setEntityType(atts.getValue("EntityType")); + m_Task.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); + m_Task.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); + m_Task.setName(name); + m_Task.setOS_Command(atts.getValue("OS_Command")); + if (m_Task.save(getTrxName(ctx)) == true){ + record_log (ctx, 1, m_Task.getName(),"Task", m_Task.get_ID(),AD_Backup_ID, Object_Status,"AD_Task",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Task")); + } + else{ + record_log (ctx, 0, m_Task.getName(),"Task", m_Task.get_ID(),AD_Backup_ID, Object_Status,"AD_Task",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Task")); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Task_ID = Env.getContextAsInt(ctx, "AD_Task_ID"); + X_AD_Task m_Task = new X_AD_Task (ctx, AD_Task_ID, null); + AttributesImpl atts = new AttributesImpl(); + createTaskBinding(atts,m_Task); + document.startElement("","","task",atts); + document.endElement("","","task"); + + } + + private static AttributesImpl createTaskBinding( AttributesImpl atts, X_AD_Task m_Task) + { + String sql = null; + String name = null; + atts.clear(); + if (m_Task.getAD_Task_ID()> 0 ){ + sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?"; + name = DB.getSQLValueString(null,sql,m_Task.getAD_Task_ID()); + } + if (name != null ) + atts.addAttribute("","","ADTaskNameID","CDATA",name); + else + atts.addAttribute("","","ADTaskNameID","CDATA",""); + atts.addAttribute("","","AccessLevel","CDATA",(m_Task.getAccessLevel () != null ? m_Task.getAccessLevel ():"")); + atts.addAttribute("","","Description","CDATA",(m_Task.getDescription () != null ? m_Task.getDescription ():"")); + atts.addAttribute("","","EntityType","CDATA",(m_Task.getEntityType () != null ? m_Task.getEntityType ():"")); + atts.addAttribute("","","Help","CDATA",(m_Task.getHelp () != null ? m_Task.getHelp ():"")); + atts.addAttribute("","","isActive","CDATA",(m_Task.isActive()== true ? "true":"false")); + atts.addAttribute("","","Name","CDATA",(m_Task.getName () != null ? m_Task.getName ():"")); + atts.addAttribute("","","OS_Command","CDATA",(m_Task.getOS_Command () != null ? m_Task.getOS_Command ():"")); + return atts; + } + +} diff --git a/base/src/org/adempiere/pipo/handler/UserRoleElementHandler.java b/base/src/org/adempiere/pipo/handler/UserRoleElementHandler.java new file mode 100644 index 0000000000..2befda888a --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/UserRoleElementHandler.java @@ -0,0 +1,139 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.compiere.model.X_AD_Role; +import org.compiere.model.X_AD_User; +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 UserRoleElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + log.info(elementValue); + int roleid =0; + int userid =0; + int orgid =0; + + StringBuffer sqlB = null; + Attributes atts = element.attributes; + if (atts.getValue("username")!=null){ + String name = atts.getValue("username"); + sqlB = new StringBuffer ("SELECT AD_User_ID FROM AD_User WHERE Name= ?"); + userid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + if (atts.getValue("rolename")!=null){ + String name = atts.getValue("rolename"); + sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); + roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + if (atts.getValue("orgname")!=null){ + String name = atts.getValue("orgname"); + sqlB = new StringBuffer ("SELECT AD_Org_ID FROM AD_Org WHERE Name= ?"); + orgid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + sqlB = new StringBuffer ("SELECT count(*) FROM AD_User_Roles WHERE AD_User_ID = ? and AD_Role_ID = ? and AD_Org_ID = "+orgid); + int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),userid,roleid); + + int AD_Backup_ID = -1; + String Object_Status = null; + if (count>0){ + //AD_Backup_ID = copyRecord("AD_Role",m_Role); + Object_Status = "Update"; + sqlB = new StringBuffer ("UPDATE AD_User_Roles ") + .append( "SET isActive = '" + atts.getValue("isActive")+"'" ) + .append( " WHERE AD_User_ID = " + userid ) + .append( " and AD_Role_ID = " + roleid ) + .append( " and AD_Org_ID = " + orgid ); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) + log.info("Update to user roles failed"); + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + sqlB = new StringBuffer ("Insert INTO AD_User_Roles") + .append( "(AD_Client_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_User_ID, AD_Role_ID, AD_Org_ID, isActive) " ) + .append( "VALUES(" ) + .append( " "+ Env.getAD_Client_ID(ctx) ) + .append( ", "+ Env.getAD_User_ID(ctx) ) + .append( ", "+ Env.getAD_User_ID(ctx) ) + .append( ", " +userid ) + .append( ", " + roleid ) + .append( ", " + orgid ) + .append( ", '" + atts.getValue("isActive")+"')" ); + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) + log.info("Insert to user roles failed"); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_User_ID = Env.getContextAsInt(ctx, X_AD_User.COLUMNNAME_AD_User_ID); + int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + int AD_Org_ID = Env.getContextAsInt(ctx, "AD_Org_ID"); + AttributesImpl atts = new AttributesImpl(); + createUserAssignBinding(atts, AD_User_ID,AD_Role_ID, AD_Org_ID); + document.startElement("", "", "userrole", atts); + document.endElement("", "", "userrole"); + } + + private AttributesImpl createUserAssignBinding(AttributesImpl atts, + int user_id, int role_id, int org_id) { + String sql = null; + String name = null; + atts.clear(); + + sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?"; + name = DB.getSQLValueString(null, sql, user_id); + atts.addAttribute("", "", "username", "CDATA", name); + + sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; + name = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "rolename", "CDATA", name); + + sql = "SELECT isActive FROM AD_User_Roles WHERE AD_User_ID=" + user_id + + " and AD_Role_ID=?"; + String TrueFalse = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isActive", "CDATA", TrueFalse); + + sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?"; + name = DB.getSQLValueString(null, sql, org_id); + atts.addAttribute("", "", "orgname", "CDATA", name); + + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/WindowAccessElementHandler.java b/base/src/org/adempiere/pipo/handler/WindowAccessElementHandler.java new file mode 100644 index 0000000000..da9347ef79 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/WindowAccessElementHandler.java @@ -0,0 +1,132 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.compiere.model.X_AD_Role; +import org.compiere.model.X_AD_Window; +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 WindowAccessElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + log.info(elementValue); + int roleid =0; + int windowid =0; + StringBuffer sqlB = null; + Attributes atts = element.attributes; + if (atts.getValue("rolename")!=null){ + String name = atts.getValue("rolename"); + sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); + roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + if (atts.getValue("windowname")!=null){ + String name = atts.getValue("windowname"); + sqlB = new StringBuffer ("SELECT AD_Window_ID FROM AD_Window WHERE Name= ?"); + windowid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + sqlB = new StringBuffer ("SELECT count(*) FROM AD_Window_Access WHERE AD_Role_ID=? and AD_Window_ID=?"); + int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,windowid); + int AD_Backup_ID = -1; + String Object_Status = null; + if (count>0){ + Object_Status = "Update"; + sqlB = new StringBuffer ("UPDATE AD_Window_Access ") + .append( "SET isActive = '" + atts.getValue("isActive") ) + .append( "', isReadWrite = '" + atts.getValue("isReadWrite") ) + .append( "' WHERE AD_Role_ID = " + roleid ) + .append( " and AD_Window_ID = " + windowid ); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) + log.info("Update to window access failed"); + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + sqlB = new StringBuffer ("Insert INTO AD_Window_Access") + .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_Role_ID, AD_Window_ID, isActive, isReadWrite) " ) + .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( ", " + roleid ) + .append( ", " + windowid ) + .append( ", '" + atts.getValue("isActive") ) + .append( "', '" + atts.getValue("isReadWrite")+"')" ); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) + log.info("Insert to window access failed"); + } + + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Window_ID = Env.getContextAsInt(ctx, X_AD_Window.COLUMNNAME_AD_Window_ID); + int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + AttributesImpl atts = new AttributesImpl(); + createWindowAccessBinding(atts, AD_Window_ID, AD_Role_ID); + document.startElement("", "", "windowaccess", atts); + document.endElement("", "", "windowaccess"); + } + + private AttributesImpl createWindowAccessBinding(AttributesImpl atts, + int window_id, int role_id) { + String sql = null; + String name = null; + atts.clear(); + + sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; + name = DB.getSQLValueString(null, sql, window_id); + atts.addAttribute("", "", "windowname", "CDATA", name); + + sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; + name = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "rolename", "CDATA", name); + + sql = "SELECT isActive FROM AD_Window_Access WHERE AD_Window_ID=" + + window_id + " and AD_Role_ID=?"; + String TrueFalse = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isActive", "CDATA", TrueFalse); + + sql = "SELECT isReadWrite FROM AD_Window_Access WHERE AD_Window_ID=" + + window_id + " and AD_Role_ID=?"; + String isReadWrite = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isReadWrite", "CDATA", isReadWrite); + + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/WindowElementHandler.java b/base/src/org/adempiere/pipo/handler/WindowElementHandler.java new file mode 100644 index 0000000000..115d11a7cf --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/WindowElementHandler.java @@ -0,0 +1,275 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.PackOut; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.MWindow; +import org.compiere.model.X_AD_Preference; +import org.compiere.model.X_AD_Tab; +import org.compiere.model.X_AD_Window; +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 WindowElementHandler extends AbstractElementHandler { + + private TabElementHandler tabHandler = new TabElementHandler(); + private PreferenceElementHandler preferenceHandler = new PreferenceElementHandler(); + + public void startElement(Properties ctx, Element element) + throws SAXException { + // Check namespace. + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("Name")); + String entitytype = atts.getValue("EntityType"); + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 + && getUpdateMode(ctx).compareTo("true") == 0) { + String name = atts.getValue("Name"); + int id = get_ID(ctx, "AD_Window", name); + MWindow m_Window = new MWindow(ctx, id, getTrxName(ctx)); + String Object_Status = null; + int AD_Backup_ID = -1; + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Window", m_Window); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + m_Window.setName(name); + + name = atts.getValue("ADImageNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Image", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Window.setAD_Image_ID(id); + } + + name = atts.getValue("ADColorNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Color", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Window.setAD_Color_ID(id); + } + + m_Window.setDescription(atts.getValue("Description").replaceAll( + "'", "''").replaceAll(",", "")); + m_Window.setEntityType(atts.getValue("EntityType")); + m_Window.setHelp(atts.getValue("Help").replaceAll("'", "''") + .replaceAll(",", "")); + m_Window.setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() : true); + m_Window.setIsBetaFunctionality(Boolean.valueOf( + atts.getValue("isBetaFunctionality")).booleanValue()); + m_Window.setIsDefault(Boolean.valueOf(atts.getValue("isDefault")) + .booleanValue()); + m_Window.setIsSOTrx(Boolean.valueOf(atts.getValue("isSOTrx")) + .booleanValue()); + m_Window.setName(atts.getValue("Name")); + m_Window.setProcessing(false); + // m_Window.setWinHeight(Integer.parseInt(atts.getValue("WinHeight"))); + // m_Window.setWinWidth + // (Integer.parseInt(atts.getValue("WinWidth"))); + m_Window.setWindowType(atts.getValue("WindowType")); + if (m_Window.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Window.getName(), "Window", m_Window + .get_ID(), AD_Backup_ID, Object_Status, "AD_Window", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Window")); + } else { + record_log(ctx, 0, m_Window.getName(), "Window", m_Window + .get_ID(), AD_Backup_ID, Object_Status, "AD_Window", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Window")); + throw new POSaveFailedException("Window"); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Window_ID = Env.getContextAsInt(ctx, "AD_Window_ID"); + PackOut packOut = (PackOut) ctx.get("PackOutProcess"); + + X_AD_Window m_Window = new X_AD_Window(ctx, AD_Window_ID, null); + AttributesImpl atts = new AttributesImpl(); + createWindowBinding(atts, m_Window); + document.startElement("", "", "window", atts); + // Tab Tag + String sql = "SELECT * FROM AD_TAB WHERE AD_WINDOW_ID = " + + AD_Window_ID; + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + String tableSql = "SELECT Name FROM AD_Table WHERE AD_Table_ID=?"; + int table_id = rs.getInt("AD_TABLE_ID"); + String name = rs.getString("NAME"); + String tablename = DB.getSQLValueString(null, tableSql, + table_id); + packOut.createTable(rs.getInt("AD_Table_ID"), atts, document); + createTab(ctx, document, rs.getInt("AD_Tab_ID")); + } + rs.close(); + pstmt.close(); + pstmt = null; + } catch (Exception e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + if (e instanceof SAXException) + throw (SAXException) e; + else if (e instanceof SQLException) + throw new DatabaseAccessException("Window", e); + else if (e instanceof RuntimeException) + throw (RuntimeException) e; + else + throw new RuntimeException("Window", e); + } finally { + try { + if (pstmt != null) + pstmt.close(); + } catch (Exception e) { + } + pstmt = null; + } + + // Loop tags. + document.endElement("", "", "window"); + + // Preference Tag + sql = "SELECT * FROM AD_PREFERENCE WHERE AD_WINDOW_ID = " + + AD_Window_ID; + pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + try { + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + createPreference(ctx, document, rs.getInt("AD_Preference_ID")); + } + rs.close(); + pstmt.close(); + pstmt = null; + } catch (Exception e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + if (e instanceof SAXException) + throw (SAXException) e; + else if (e instanceof SQLException) + throw new DatabaseAccessException("Window", e); + else if (e instanceof RuntimeException) + throw (RuntimeException) e; + else + throw new RuntimeException("Window", e); + } finally { + try { + if (pstmt != null) + pstmt.close(); + } catch (Exception e) { + } + pstmt = null; + } + } + + private void createPreference(Properties ctx, TransformerHandler document, + int AD_Preference_ID) throws SAXException { + Env.setContext(ctx, X_AD_Preference.COLUMNNAME_AD_Preference_ID, + AD_Preference_ID); + preferenceHandler.create(ctx, document); + ctx.remove(X_AD_Preference.COLUMNNAME_AD_Preference_ID); + } + + private void createTab(Properties ctx, TransformerHandler document, + int AD_Tab_ID) throws SAXException { + Env.setContext(ctx, X_AD_Tab.COLUMNNAME_AD_Tab_ID, AD_Tab_ID); + tabHandler.create(ctx, document); + ctx.remove(X_AD_Tab.COLUMNNAME_AD_Tab_ID); + } + + private AttributesImpl createWindowBinding(AttributesImpl atts, + X_AD_Window m_Window) { + atts.clear(); + String sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; + String name = DB.getSQLValueString(null, sql, m_Window + .getAD_Window_ID()); + atts.addAttribute("", "", "ADWindowNameID", "CDATA", name); + if (m_Window.getAD_Image_ID() > 0) { + sql = "SELECT Name FROM AD_Image WHERE AD_Image_ID=?"; + name = DB.getSQLValueString(null, sql, m_Window.getAD_Image_ID()); + } + if (name != null) + atts.addAttribute("", "", "ADImageNameID", "CDATA", name); + else + atts.addAttribute("", "", "ADImageNameID", "CDATA", ""); + if (m_Window.getAD_Color_ID() > 0) { + sql = "SELECT Name FROM AD_Color WHERE AD_Color_ID=?"; + name = DB.getSQLValueString(null, sql, m_Window.getAD_Color_ID()); + } + if (name != null) + atts.addAttribute("", "", "ADColorNameID", "CDATA", name); + else + atts.addAttribute("", "", "ADColorNameID", "CDATA", ""); + atts.addAttribute("", "", "Description", "CDATA", (m_Window + .getDescription() != null ? m_Window.getDescription() : "")); + atts.addAttribute("", "", "EntityType", "CDATA", (m_Window + .getEntityType() != null ? m_Window.getEntityType() : "")); + atts.addAttribute("", "", "Help", "CDATA", + (m_Window.getHelp() != null ? m_Window.getHelp() : "")); + atts.addAttribute("", "", "isBetaFunctionality", "CDATA", (m_Window + .isBetaFunctionality() == true ? "true" : "false")); + atts.addAttribute("", "", "isDefault", "CDATA", + (m_Window.isDefault() == true ? "true" : "false")); + atts.addAttribute("", "", "isSOTrx", "CDATA", + (m_Window.isSOTrx() == true ? "true" : "false")); + atts.addAttribute("", "", "isActive", "CDATA", + (m_Window.isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "Name", "CDATA", + (m_Window.getName() != null ? m_Window.getName() : "")); + atts.addAttribute("", "", "isProcessing", "CDATA", (m_Window + .isProcessing() == true ? "true" : "false")); + atts.addAttribute("", "", "WinHeight", "CDATA", (m_Window + .getWinHeight() > 0 ? "" + m_Window.getWinHeight() : "")); + atts + .addAttribute("", "", "WinWidth", "CDATA", (m_Window + .getWinWidth() > 0 ? "" + m_Window.getWinWidth() : "")); + atts.addAttribute("", "", "WindowType", "CDATA", (m_Window + .getWindowType() != null ? m_Window.getWindowType() : "")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/WorkbenchElementHandler.java b/base/src/org/adempiere/pipo/handler/WorkbenchElementHandler.java new file mode 100644 index 0000000000..655c52935f --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/WorkbenchElementHandler.java @@ -0,0 +1,202 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.compiere.model.X_AD_Package_Exp_Detail; +import org.compiere.model.X_AD_Workbench; +import org.compiere.model.X_AD_WorkbenchWindow; +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 WorkbenchElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + int AD_Backup_ID = -1; + String Object_Status = null; + Attributes atts = element.attributes; + log.info(elementValue+" "+atts.getValue("ADWorkbenchNameID")); + String entitytype = atts.getValue("EntityType"); + String name = atts.getValue("ADWorkbenchNameID"); + if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0 && getUpdateMode(ctx).compareTo("true") == 0 ) { + int id = get_ID(ctx, "AD_Workbench", name); + X_AD_Workbench m_Workbench = new X_AD_Workbench(ctx, id, getTrxName(ctx)); + if (id > 0){ + AD_Backup_ID = copyRecord(ctx, "AD_Workbench",m_Workbench); + Object_Status = "Update"; + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + } + + int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID")); + int columnid = get_IDWithMasterAndColumn (ctx, "AD_Column","ColumnName", atts.getValue("ADColumnNameID"), "AD_Table", tableid); + m_Workbench.setAD_Column_ID(columnid); + m_Workbench.setDescription(atts.getValue("Description").replaceAll("'","''").replaceAll(",","")); + m_Workbench.setEntityType(atts.getValue("EntityType")); + m_Workbench.setHelp(atts.getValue("Help").replaceAll("'","''").replaceAll(",","")); + m_Workbench.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); + m_Workbench.setName(atts.getValue("Name")); + //m_Workbench.setPA_Goal_ID(Integer.parseInt(atts.getValue("PAGoalID"))); + if (m_Workbench.save(getTrxName(ctx)) == true){ + record_log (ctx, 1, m_Workbench.getName(),"Workbench", m_Workbench.get_ID(),AD_Backup_ID, Object_Status,"AD_Workbench",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Workbench")); + } + else{ + record_log (ctx, 0, m_Workbench.getName(),"Workbench", m_Workbench.get_ID(),AD_Backup_ID, Object_Status,"AD_Workbench",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Workbench")); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Workbench_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workbench_ID); + X_AD_Workbench m_Workbench = new X_AD_Workbench (ctx, AD_Workbench_ID, null); + AttributesImpl atts = new AttributesImpl(); + createWorkbenchBinding(atts,m_Workbench); + document.startElement("","","workbench",atts); + //Workbenchwindow tags + String sqlP = "SELECT * FROM AD_WorkbenchWindow WHERE AD_WORKBENCH_ID = " + AD_Workbench_ID; + PreparedStatement pstmtP = null; + pstmtP = DB.prepareStatement (sqlP, getTrxName(ctx)); + try { + ResultSet rsP = pstmtP.executeQuery(); + while (rsP.next()) + { + X_AD_WorkbenchWindow m_Workbenchwindow = new X_AD_WorkbenchWindow (ctx, rsP.getInt("AD_Workbench_Window_ID"), null); + atts = createWorkbenchWindowBinding(atts,m_Workbenchwindow); + document.startElement("","","workbenchwindow",atts); + document.endElement("","","workbenchwindow"); + } + rsP.close(); + pstmtP.close(); + pstmtP = null; + } + catch (Exception e) + { + log.log(Level.SEVERE,"getWorkbench_Window", e); + } + finally + { + try { + if (pstmtP != null) + pstmtP.close (); + } + catch (Exception e) + {} + pstmtP = null; + } + document.endElement("","","workbench"); + + } + + private AttributesImpl createWorkbenchBinding( AttributesImpl atts, X_AD_Workbench m_Workbench) + { + String sql = null; + String name = null; + atts.clear(); + if (m_Workbench.getAD_Workbench_ID()> 0 ){ + sql = "SELECT Name FROM AD_Workbench WHERE AD_Workbench_ID=?"; + name = DB.getSQLValueString(null,sql,m_Workbench.getAD_Workbench_ID()); + } + if (name != null ) + atts.addAttribute("","","ADWorkbenchNameID","CDATA",name); + else + atts.addAttribute("","","ADWorkbenchNameID","CDATA",""); + if (m_Workbench.getAD_Column_ID()> 0 ){ + sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null,sql,m_Workbench.getAD_Column_ID()); + } + if (name != null ) + atts.addAttribute("","","ADColumnNameID","CDATA",name); + else + atts.addAttribute("","","ADColumnNameID","CDATA",""); + atts.addAttribute("","","Description","CDATA",(m_Workbench.getDescription () != null ? m_Workbench.getDescription ():"")); + atts.addAttribute("","","EntityType","CDATA",(m_Workbench.getEntityType () != null ? m_Workbench.getEntityType ():"")); + atts.addAttribute("","","Help","CDATA",(m_Workbench.getHelp () != null ? m_Workbench.getHelp ():"")); + atts.addAttribute("","","isActive","CDATA",(m_Workbench.isActive()== true ? "true":"false")); + atts.addAttribute("","","Name","CDATA",(m_Workbench.getName () != null ? m_Workbench.getName ():"")); + //atts.addAttribute("","","PA_Goal_ID","CDATA",(m_Workbench.getPA_Goal_ID() > 0 ? "" + m_Workbench.getPA_Goal_ID ():"")); + return atts; + } + + private AttributesImpl createWorkbenchWindowBinding( AttributesImpl atts, X_AD_WorkbenchWindow m_Workbenchwindow) + { + String sql = null; + String name = null; + atts.clear(); + if (m_Workbenchwindow.getAD_Process_ID()> 0 ){ + sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; + name = DB.getSQLValueString(null,sql,m_Workbenchwindow.getAD_Process_ID()); + atts.addAttribute("","","name","CDATA",name); + } + else + atts.addAttribute("","","name","CDATA",""); + if (m_Workbenchwindow.getAD_Workbench_ID()> 0 ){ + sql = "SELECT Name FROM AD_Workbench WHERE AD_Workbench_ID=?"; + name = DB.getSQLValueString(null,sql,m_Workbenchwindow.getAD_Workbench_ID()); + } + if (name != null ) + atts.addAttribute("","","ADWorkbenchNameID","CDATA",name); + else + atts.addAttribute("","","ADWorkbenchNameID","CDATA",""); + if (m_Workbenchwindow.getAD_Form_ID()> 0 ){ + sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?"; + name = DB.getSQLValueString(null,sql,m_Workbenchwindow.getAD_Form_ID()); + } + if (name != null ) + atts.addAttribute("","","ADFormNameID","CDATA",name); + else + atts.addAttribute("","","ADFormNameID","CDATA",""); + if (m_Workbenchwindow.getAD_Window_ID()> 0 ){ + sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; + name = DB.getSQLValueString(null,sql,m_Workbenchwindow.getAD_Window_ID()); + } + if (name != null ) + atts.addAttribute("","","ADWindowNameID","CDATA",name); + else + atts.addAttribute("","","ADWindowNameID","CDATA",""); + if (m_Workbenchwindow.getAD_Task_ID()> 0 ){ + sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?"; + name = DB.getSQLValueString(null,sql,m_Workbenchwindow.getAD_Task_ID()); + } + if (name != null ) + atts.addAttribute("","","ADTaskNameID","CDATA",name); + else + atts.addAttribute("","","ADTaskNameID","CDATA",""); + atts.addAttribute("","","EntityType","CDATA",(m_Workbenchwindow.getEntityType () != null ? m_Workbenchwindow.getEntityType ():"")); + atts.addAttribute("","","SeqNo","CDATA",(m_Workbenchwindow.getSeqNo () > 0 ? "" + m_Workbenchwindow.getSeqNo ():"")); + atts.addAttribute("","","isActive","CDATA",(m_Workbenchwindow.isActive()== true ? "true":"false")); + atts.addAttribute("","","isPrimary","CDATA",(m_Workbenchwindow.isPrimary()== true ? "true":"false")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/WorkflowAccessElementHandler.java b/base/src/org/adempiere/pipo/handler/WorkflowAccessElementHandler.java new file mode 100644 index 0000000000..bdfa237964 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/WorkflowAccessElementHandler.java @@ -0,0 +1,136 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.compiere.model.X_AD_Role; +import org.compiere.model.X_AD_Workflow; +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 WorkflowAccessElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + String elementValue = element.getElementValue(); + log.info(elementValue); + int roleid =0; + int workflowid =0; + StringBuffer sqlB = null; + Attributes atts = element.attributes; + if (atts.getValue("rolename")!=null){ + String name = atts.getValue("rolename"); + sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?"); + roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + if (atts.getValue("workflowname")!=null){ + String name = atts.getValue("workflowname"); + sqlB = new StringBuffer ("SELECT AD_Workflow_ID FROM AD_Workflow WHERE Name= ?"); + workflowid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name); + } + + sqlB = new StringBuffer ("SELECT count(*) FROM AD_Workflow_Access WHERE AD_Role_ID=? and AD_Workflow_ID=?"); + int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,workflowid); + int AD_Backup_ID = -1; + String Object_Status = null; + if (count>0){ + Object_Status = "Update"; + sqlB = new StringBuffer ("UPDATE AD_Workflow_Access ") + .append( "SET isActive = '" + atts.getValue("isActive") ) + .append( "', isReadWrite = '" + atts.getValue("isReadWrite") ) + .append( "' WHERE AD_Role_ID = " + roleid ) + .append( " and AD_Workflow_ID = " + workflowid ); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) { + log.info("Update to workflow access failed"); + throw new DatabaseAccessException("Update to workflow access failed"); + } + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + sqlB = new StringBuffer ("Insert INTO AD_Workflow_Access") + .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_Role_ID, AD_Workflow_ID, isActive, isReadWrite) " ) + .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( ", " + roleid ) + .append( ", " + workflowid ) + .append( ", '" + atts.getValue("isActive") ) + .append( "', '" + atts.getValue("isReadWrite")+"')" ); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) { + log.info("Insert to workflow access failed"); + throw new DatabaseAccessException("Insert to workflow access failed"); + } + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Workflow_ID = Env.getContextAsInt(ctx, X_AD_Workflow.COLUMNNAME_AD_Workflow_ID); + int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + AttributesImpl atts = new AttributesImpl(); + createWorkflowAccessBinding(atts, AD_Workflow_ID, AD_Role_ID); + document.startElement("", "", "workflowaccess", atts); + document.endElement("", "", "workflowaccess"); + } + + private AttributesImpl createWorkflowAccessBinding(AttributesImpl atts, + int workflow_id, int role_id) { + String sql = null; + String name = null; + atts.clear(); + + sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?"; + name = DB.getSQLValueString(null, sql, workflow_id); + atts.addAttribute("", "", "workflowname", "CDATA", name); + + sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; + name = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "rolename", "CDATA", name); + + sql = "SELECT isActive FROM AD_Workflow_Access WHERE AD_Workflow_ID=" + + workflow_id + " and AD_Role_ID=?"; + String TrueFalse = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isActive", "CDATA", TrueFalse); + + sql = "SELECT isReadWrite FROM AD_Workflow_Access WHERE AD_Workflow_ID=" + + workflow_id + " and AD_Role_ID=?"; + String isReadWrite = DB.getSQLValueString(null, sql, role_id); + atts.addAttribute("", "", "isReadWrite", "CDATA", isReadWrite); + + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/WorkflowElementHandler.java b/base/src/org/adempiere/pipo/handler/WorkflowElementHandler.java new file mode 100644 index 0000000000..ba2b3c990a --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/WorkflowElementHandler.java @@ -0,0 +1,370 @@ +/****************************************************************************** + * 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.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.DatabaseAccessException; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.X_AD_Package_Exp_Detail; +import org.compiere.model.X_AD_WF_NextCondition; +import org.compiere.model.X_AD_WF_Node; +import org.compiere.model.X_AD_WF_NodeNext; +import org.compiere.model.X_AD_Workflow; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.wf.MWorkflow; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +public class WorkflowElementHandler extends AbstractElementHandler { + + private WorkflowNodeElementHandler nodeHandler = new WorkflowNodeElementHandler(); + private WorkflowNodeNextElementHandler nodeNextHandler = new WorkflowNodeNextElementHandler(); + private WorkflowNodeNextConditionElementHandler nextConditionHandler = new WorkflowNodeNextConditionElementHandler(); + + public void startElement(Properties ctx, Element element) + throws SAXException { + Attributes atts = element.attributes; + String elementValue = element.getElementValue(); + log.info(elementValue + " " + atts.getValue("Name")); + String entitytype = atts.getValue("EntityType"); + log.info("entitytype " + atts.getValue("EntityType")); + + if (entitytype.equals("U") || entitytype.equals("D") + && getUpdateMode(ctx).equals("true")) { + log.info("entitytype is a U or D"); + + String workflowName = atts.getValue("Name"); + + int id = get_IDWithColumn(ctx, "AD_Workflow", "name", workflowName); + + MWorkflow m_Workflow = new MWorkflow(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Workflow", m_Workflow); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + + String name = atts.getValue("ADWorkflowResponsibleNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_WF_Responsible", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Workflow.setAD_WF_Responsible_ID(id); + } + + name = atts.getValue("ADTableNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Table", "TableName", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Workflow.setAD_Table_ID(id); + + } + + name = atts.getValue("ADWorkflowProcessorNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_WorkflowProcessor", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_Workflow.setAD_WorkflowProcessor_ID(id); + + } + m_Workflow.setName(workflowName); + m_Workflow.setAccessLevel(atts.getValue("AccessLevel")); + m_Workflow.setDescription(atts.getValue("Description").replaceAll( + "'", "''").replaceAll(",", "")); + m_Workflow.setHelp(atts.getValue("Help").replaceAll("'", "''") + .replaceAll(",", "")); + m_Workflow.setDurationUnit(atts.getValue("DurationUnit")); + m_Workflow.setAuthor(atts.getValue("Author")); + m_Workflow.setVersion(Integer.valueOf(atts.getValue("Version"))); + m_Workflow.setPriority(Integer.valueOf(atts.getValue("Priority"))); + m_Workflow.setLimit(Integer.valueOf(atts.getValue("Limit"))); + m_Workflow.setDuration(Integer.valueOf(atts.getValue("Duration"))); + m_Workflow.setCost(Integer.valueOf(atts.getValue("Cost"))); + m_Workflow.setWorkingTime(Integer.valueOf(atts + .getValue("WorkingTime"))); + m_Workflow.setWaitingTime(Integer.valueOf(atts + .getValue("WaitingTime"))); + m_Workflow.setPublishStatus(atts.getValue("PublishStatus")); + m_Workflow.setWorkflowType(atts.getValue("WorkflowType")); + m_Workflow.setDocValueLogic(atts.getValue("DocValueLogic")); + m_Workflow.setIsValid(atts.getValue("isValid") != null ? Boolean + .valueOf(atts.getValue("isValid")).booleanValue() : true); + m_Workflow.setEntityType(atts.getValue("EntityType")); + m_Workflow.setAD_WF_Node_ID(-1); + // log.info("in3"); + getDocumentAttributes(ctx).clear(); + log.info("about to execute m_Workflow.save"); + if (m_Workflow.save(getTrxName(ctx)) == true) { + log.info("m_Workflow save success"); + record_log(ctx, 1, m_Workflow.getName(), "Workflow", m_Workflow + .get_ID(), AD_Backup_ID, Object_Status, "AD_Workflow", + get_IDWithColumn(ctx, "AD_Workflow", "Name", + "AD_Workflow")); + } else { + log.info("m_Workflow save failure"); + record_log(ctx, 0, m_Workflow.getName(), "Workflow", m_Workflow + .get_ID(), AD_Backup_ID, Object_Status, "AD_Workflow", + get_IDWithColumn(ctx, "AD_Workflow", "Name", + "AD_Workflow")); + throw new POSaveFailedException("MWorkflow"); + } + } else { + log.info("entitytype is not a U or D"); + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Workflow_ID = Env.getContextAsInt(ctx, + X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID); + String sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID= " + + AD_Workflow_ID; + int ad_wf_nodenext_id = 0; + int ad_wf_nodenextcondition_id = 0; + AttributesImpl atts = new AttributesImpl(); + + PreparedStatement pstmt = null; + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + + try { + + ResultSet rs = pstmt.executeQuery(); + + while (rs.next()) { + X_AD_Workflow m_Workflow = new X_AD_Workflow(ctx, + AD_Workflow_ID, null); + X_AD_WF_Node m_WF_Node = null; + createWorkflowBinding(atts, m_Workflow); + document.startElement("", "", "workflow", atts); + String sql1 = "SELECT * FROM AD_WF_Node WHERE AD_Workflow_ID = " + + AD_Workflow_ID; + + PreparedStatement pstmt1 = null; + pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx)); + + try { + + // Generated workflowNodeNext(s) and + // workflowNodeNextCondition(s) + ResultSet rs1 = pstmt1.executeQuery(); + while (rs1.next()) { + + int nodeId = rs1.getInt("AD_WF_Node_ID"); + createNode(ctx, document, nodeId); + + ad_wf_nodenext_id = 0; + + sql = "SELECT ad_wf_nodenext_id from ad_wf_nodenext WHERE ad_wf_node_id = ?"; + ad_wf_nodenext_id = DB.getSQLValue(null, sql, m_WF_Node + .getAD_WF_Node_ID()); + if (ad_wf_nodenext_id > 0) { + createNodeNext(ctx, document, ad_wf_nodenext_id); + + ad_wf_nodenextcondition_id = 0; + + sql = "SELECT ad_wf_nextcondition_id from ad_wf_nextcondition WHERE ad_wf_nodenext_id = ?"; + ad_wf_nodenextcondition_id = DB.getSQLValue(null, + sql, m_WF_Node.getAD_WF_Node_ID()); + log + .info("ad_wf_nodenextcondition_id: " + + String + .valueOf(ad_wf_nodenextcondition_id)); + if (ad_wf_nodenextcondition_id > 0) { + createNodeNextCondition(ctx, document, + ad_wf_nodenextcondition_id); + } + } + + } + + rs1.close(); + pstmt1.close(); + pstmt1 = null; + } finally { + try { + if (pstmt1 != null) + pstmt1.close(); + } catch (Exception e) { + } + pstmt1 = null; + } + document.endElement("", "", "workflow"); + } + rs.close(); + pstmt.close(); + pstmt = null; + } catch (Exception e) { + log.log(Level.SEVERE, "Workflow", e); + if (e instanceof SAXException) + throw (SAXException) e; + else if (e instanceof SQLException) + throw new DatabaseAccessException("Workflow", e); + else + throw new RuntimeException("Workflow", e); + } finally { + try { + if (pstmt != null) + pstmt.close(); + } catch (Exception e) { + } + pstmt = null; + } + } + + private void createNodeNextCondition(Properties ctx, + TransformerHandler document, int ad_wf_nodenextcondition_id) + throws SAXException { + Env.setContext(ctx, + X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID, + ad_wf_nodenextcondition_id); + nextConditionHandler.create(ctx, document); + ctx.remove(X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID); + } + + private void createNodeNext(Properties ctx, TransformerHandler document, + int ad_wf_nodenext_id) throws SAXException { + Env.setContext(ctx, X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID, + ad_wf_nodenext_id); + nodeNextHandler.create(ctx, document); + ctx.remove(X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID); + } + + private void createNode(Properties ctx, TransformerHandler document, + int AD_WF_Node_ID) throws SAXException { + Env.setContext(ctx, X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID, + AD_WF_Node_ID); + nodeHandler.create(ctx, document); + ctx.remove(X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID); + } + + private AttributesImpl createWorkflowBinding(AttributesImpl atts, + X_AD_Workflow m_Workflow) { + String sql = null; + String name = null; + atts.clear(); + atts.addAttribute("", "", "Name", "CDATA", + (m_Workflow.getName() != null ? m_Workflow.getName() : "")); + if (m_Workflow.getAD_Table_ID() > 0) { + sql = "SELECT Name FROM AD_Table WHERE AD_Table_ID=?"; + name = DB.getSQLValueString(null, sql, m_Workflow.getAD_Table_ID()); + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADTableNameID", "CDATA", ""); + + if (m_Workflow.getAD_WF_Node_ID() > 0) { + sql = "SELECT Name FROM AD_WF_Node WHERE AD_WF_Node_ID=?"; + name = DB.getSQLValueString(null, sql, m_Workflow + .getAD_WF_Node_ID()); + atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA", ""); + if (m_Workflow.getAD_WF_Responsible_ID() > 0) { + sql = "SELECT Name FROM AD_WF_Responsible WHERE AD_WF_Responsible_ID=?"; + name = DB.getSQLValueString(null, sql, m_Workflow + .getAD_WF_Responsible_ID()); + atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA", + name); + } else + atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA", + ""); + if (m_Workflow.getAD_WorkflowProcessor_ID() > 0) { + sql = "SELECT Name FROM AD_WorkflowProcessor_ID WHERE AD_WorkflowProcessor_ID=?"; + name = DB.getSQLValueString(null, sql, m_Workflow + .getAD_WorkflowProcessor_ID()); + atts.addAttribute("", "", "ADWorkflowProcessorNameID", "CDATA", + name); + } else + atts.addAttribute("", "", "ADWorkflowProcessorNameID", "CDATA", ""); + atts.addAttribute("", "", "AccessLevel", "CDATA", (m_Workflow + .getAccessLevel() != null ? m_Workflow.getAccessLevel() : "")); + atts + .addAttribute("", "", "DurationUnit", "CDATA", (m_Workflow + .getDurationUnit() != null ? m_Workflow + .getDurationUnit() : "")); + atts.addAttribute("", "", "Help", "CDATA", + (m_Workflow.getHelp() != null ? m_Workflow.getHelp() : "")); + atts.addAttribute("", "", "Description", "CDATA", (m_Workflow + .getDescription() != null ? m_Workflow.getDescription() : "")); + atts.addAttribute("", "", "EntityType", "CDATA", (m_Workflow + .getEntityType() != null ? m_Workflow.getEntityType() : "")); + atts.addAttribute("", "", "Author", "CDATA", + (m_Workflow.getAuthor() != null ? m_Workflow.getAuthor() : "")); + atts.addAttribute("", "", "Version", "CDATA", ("" + + m_Workflow.getVersion() != null ? "" + + m_Workflow.getVersion() : "")); + // FIXME: Handle dates + // atts.addAttribute("","","ValidFrom","CDATA",(m_Workflow.getValidFrom + // ().toGMTString() != null ? + // m_Workflow.getValidFrom().toGMTString():"")); + // atts.addAttribute("","","ValidTo","CDATA",(m_Workflow.getValidTo + // ().toGMTString() != null ? + // m_Workflow.getValidTo().toGMTString():"")); + atts.addAttribute("", "", "Priority", "CDATA", ("" + m_Workflow + .getPriority())); + atts.addAttribute("", "", "Limit", "CDATA", + ("" + m_Workflow.getLimit())); + atts.addAttribute("", "", "Duration", "CDATA", ("" + m_Workflow + .getDuration())); + atts.addAttribute("", "", "Cost", "CDATA", ("" + m_Workflow.getCost())); + atts.addAttribute("", "", "WorkingTime", "CDATA", ("" + m_Workflow + .getWorkingTime())); + atts.addAttribute("", "", "WaitingTime", "CDATA", ("" + m_Workflow + .getWaitingTime())); + atts.addAttribute("", "", "PublishStatus", "CDATA", (m_Workflow + .getPublishStatus() != null ? m_Workflow.getPublishStatus() + : "")); + atts + .addAttribute("", "", "WorkflowType", "CDATA", (m_Workflow + .getWorkflowType() != null ? m_Workflow + .getWorkflowType() : "")); + atts.addAttribute("", "", "DocValueLogic", "CDATA", (m_Workflow + .getDocValueLogic() != null ? m_Workflow.getDocValueLogic() + : "")); + atts.addAttribute("", "", "isValid", "CDATA", + (m_Workflow.isValid() == true ? "true" : "false")); + // Doesn't appear to be necessary + // atts.addAttribute("","","SetupTime","CDATA",(""+m_Workflow.getSetupTime() + // != null ? ""+m_Workflow.getSetupTime():"")); + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/WorkflowNodeElementHandler.java b/base/src/org/adempiere/pipo/handler/WorkflowNodeElementHandler.java new file mode 100644 index 0000000000..94c62d79c0 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/WorkflowNodeElementHandler.java @@ -0,0 +1,345 @@ +/****************************************************************************** + * 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.exception.POSaveFailedException; +import org.compiere.model.X_AD_WF_Node; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.wf.MWFNode; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +public class WorkflowNodeElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) + throws SAXException { + Attributes atts = element.attributes; + String elementValue = element.getElementValue(); + log.info(elementValue + " " + atts.getValue("Name")); + String entitytype = atts.getValue("EntityType"); + log.info("entitytype " + atts.getValue("EntityType")); + + if (entitytype.equals("U") || entitytype.equals("D") + && getUpdateMode(ctx).equals("true")) { + log.info("entitytype is a U or D"); + + String workflowName = atts.getValue("ADWorkflowNameID"); + int workflowId = get_IDWithColumn(ctx, "AD_Workflow", "name", + workflowName); + if (workflowId <= 0) { + element.defer = true; + return; + } + + String workflowNodeName = atts.getValue("Name"); + + StringBuffer sqlB = new StringBuffer( + "SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?"); + + int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), + workflowId, workflowNodeName); + + MWFNode m_WFNode = new MWFNode(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_WF_Node", m_WFNode); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + m_WFNode.setName(workflowNodeName); + m_WFNode.setAD_Workflow_ID(workflowId); + + String name = atts.getValue("ADProcessNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Process", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_WFNode.setAD_Process_ID(id); + } + + name = atts.getValue("ADFormNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Form", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_WFNode.setAD_Form_ID(id); + } + + name = atts.getValue("ADWorkflowResponsibleNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_WF_Responsible", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_WFNode.setAD_WF_Responsible_ID(id); + } + + name = atts.getValue("ADWindowNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Window", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_WFNode.setAD_Window_ID(id); + } + + name = atts.getValue("ADImageNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_Image", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_WFNode.setAD_Image_ID(id); + } + + name = atts.getValue("ADWorkflowBlockNameID"); + if (name != null && name.trim().length() > 0) { + id = get_IDWithColumn(ctx, "AD_WF_Block", "Name", name); + if (id <= 0) { + element.defer = true; + return; + } + m_WFNode.setAD_WF_Block_ID(id); + } + /* + * FIXME: Do we need TaskName ? if + * (atts.getValue("ADTaskNameID")!=null){ String name = + * atts.getValue("ADTaskNameID"); sqlB = new StringBuffer ("SELECT + * AD_Task_ID FROM AD_Task WHERE Name= ?"); taskid = + * DB.getSQLValue(m_trxName,sqlB.toString(),name); } + */ + m_WFNode.setEntityType(atts.getValue("EntityType")); + m_WFNode.setAction(atts.getValue("Action")); + m_WFNode.setDocAction(atts.getValue("DocAction")); + m_WFNode.setDescription(atts.getValue("Description").replaceAll( + "'", "''").replaceAll(",", "")); + m_WFNode.setJoinElement(atts.getValue("JoinElement")); + m_WFNode.setSplitElement(atts.getValue("SplitElement")); + m_WFNode.setXPosition(Integer.valueOf(atts.getValue("XPosition"))); + m_WFNode.setYPosition(Integer.valueOf(atts.getValue("YPosition"))); + m_WFNode.setWaitingTime(Integer.valueOf(atts + .getValue("WaitingTime"))); + m_WFNode.setWaitTime(Integer.valueOf(atts.getValue("WaitTime"))); + m_WFNode.setWorkingTime(Integer.valueOf(atts + .getValue("WorkingTime"))); + m_WFNode.setCost(new BigDecimal(atts.getValue("Cost"))); + m_WFNode.setDuration(Integer.valueOf(atts.getValue("Duration"))); + m_WFNode.setPriority(Integer.valueOf(atts.getValue("Priority"))); + // FIXME: Failing for some reason on a "" + // m_WFNode.setStartMode(atts.getValue("StartMode")); + // FIXME: Failing for some reason on a "" + // m_WFNode.setSubflowExecution(atts.getValue("SubflowExecution")); + m_WFNode.setIsCentrallyMaintained(Boolean.valueOf( + atts.getValue("IsCentrallyMaintained")).booleanValue()); + m_WFNode.setDynPriorityChange(new BigDecimal(atts + .getValue("DynPriorityChange"))); + // m_WFNode.setAccessLevel (atts.getValue("AccessLevel")); + // FIXME: Failing for some reason on a "" + // m_WFNode.setDynPriorityUnit (atts.getValue("DynPriorityUnit")); + m_WFNode.setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() : true); + // log.info("in3"); + getDocumentAttributes(ctx).clear(); + log.info("about to execute m_WFNode.save"); + if (m_WFNode.save(getTrxName(ctx)) == true) { + log.info("m_WFNode save success"); + record_log(ctx, 1, m_WFNode.getName(), "WFNode", m_WFNode + .get_ID(), AD_Backup_ID, Object_Status, "AD_WF_Node", + get_IDWithColumn(ctx, "AD_WF_Node", "Name", + "AD_WF_Node")); + } else { + log.info("m_WFNode save failure"); + record_log(ctx, 0, m_WFNode.getName(), "WFNode", m_WFNode + .get_ID(), AD_Backup_ID, Object_Status, "AD_WF_Node", + get_IDWithColumn(ctx, "AD_WF_Node", "Name", + "AD_WF_Node")); + throw new POSaveFailedException("WorkflowNode"); + } + } else { + log.info("entitytype is not a U or D"); + + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_WF_Node_ID = Env.getContextAsInt(ctx, + X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID); + AttributesImpl atts = new AttributesImpl(); + X_AD_WF_Node m_WF_Node = new X_AD_WF_Node(ctx, AD_WF_Node_ID, + getTrxName(ctx)); + + createWorkflowNodeBinding(atts, m_WF_Node); + document.startElement("", "", "workflowNode", atts); + document.endElement("", "", "workflowNode"); + } + + private AttributesImpl createWorkflowNodeBinding(AttributesImpl atts, + X_AD_WF_Node m_WF_Node) { + String sql = null; + String name = null; + atts.clear(); + + atts.addAttribute("", "", "Name", "CDATA", + (m_WF_Node.getName() != null ? m_WF_Node.getName() : "")); + + if (m_WF_Node.getAD_Workflow_ID() > 0) { + sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_Node + .getAD_Workflow_ID()); + atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", ""); + + if (m_WF_Node.getAD_Window_ID() > 0) { + sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Window_ID()); + } + if (name != null) + atts.addAttribute("", "", "ADWindowNameID", "CDATA", name); + else + atts.addAttribute("", "", "ADWindowNameID", "CDATA", ""); + + if (m_WF_Node.getAD_Task_ID() > 0) { + sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Task_ID()); + } + if (name != null) + atts.addAttribute("", "", "ADTaskNameID", "CDATA", name); + else + atts.addAttribute("", "", "ADTaskNameID", "CDATA", ""); + + if (m_WF_Node.getAD_Process_ID() > 0) { + sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?"; + name = DB + .getSQLValueString(null, sql, m_WF_Node.getAD_Process_ID()); + atts.addAttribute("", "", "ADProcessNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADProcessNameID", "CDATA", ""); + if (m_WF_Node.getAD_Form_ID() > 0) { + sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Form_ID()); + atts.addAttribute("", "", "ADFormNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADFormNameID", "CDATA", ""); + if (m_WF_Node.getAD_WF_Block_ID() > 0) { + sql = "SELECT Name FROM AD_WF_Block WHERE AD_WF_Block_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_Node + .getAD_WF_Block_ID()); + atts.addAttribute("", "", "ADWorkflowBlockNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADWorkflowBlockNameID", "CDATA", ""); + if (m_WF_Node.getAD_WF_Responsible_ID() > 0) { + sql = "SELECT Name FROM AD_WF_Responsible WHERE AD_WF_Responsible_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_Node + .getAD_WF_Responsible_ID()); + atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA", + name); + } else + atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA", + ""); + + if (m_WF_Node.getAD_Image_ID() > 0) { + sql = "SELECT Name FROM AD_Image WHERE AD_Image_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Image_ID()); + } + if (name != null) + atts.addAttribute("", "", "ADImageNameID", "CDATA", name); + else + atts.addAttribute("", "", "ADImageNameID", "CDATA", ""); + if (m_WF_Node.getAD_Column_ID() > 0) { + sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Column_ID()); + atts.addAttribute("", "", "ADColumnNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADColumnNameID", "CDATA", ""); + atts.addAttribute("", "", "isActive", "CDATA", + (m_WF_Node.isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "Description", "CDATA", (m_WF_Node + .getDescription() != null ? m_WF_Node.getDescription() : "")); + atts.addAttribute("", "", "Help", "CDATA", + (m_WF_Node.getHelp() != null ? m_WF_Node.getHelp() : "")); + atts.addAttribute("", "", "isCentrallyMaintained", "CDATA", (m_WF_Node + .isCentrallyMaintained() == true ? "true" : "false")); + + atts.addAttribute("", "", "Action", "CDATA", + (m_WF_Node.getAction() != null ? m_WF_Node.getAction() : "")); + atts.addAttribute("", "", "EntityType", "CDATA", (m_WF_Node + .getEntityType() != null ? m_WF_Node.getEntityType() : "")); + atts.addAttribute("", "", "XPosition", "CDATA", ("" + m_WF_Node + .getXPosition())); + atts.addAttribute("", "", "YPosition", "CDATA", ("" + m_WF_Node + .getYPosition())); + atts.addAttribute("", "", "SubflowExecution", "CDATA", (m_WF_Node + .getSubflowExecution() != null ? m_WF_Node + .getSubflowExecution() : "")); + atts.addAttribute("", "", "StartMode", "CDATA", (m_WF_Node + .getStartMode() != null ? m_WF_Node.getStartMode() : "")); + atts.addAttribute("", "", "Priority", "CDATA", ("" + m_WF_Node + .getPriority())); + atts.addAttribute("", "", "Duration", "CDATA", ("" + m_WF_Node + .getDuration())); + atts.addAttribute("", "", "Cost", "CDATA", ("" + m_WF_Node.getCost())); + atts.addAttribute("", "", "WorkingTime", "CDATA", ("" + m_WF_Node + .getWorkingTime())); + atts.addAttribute("", "", "WaitingTime", "CDATA", ("" + m_WF_Node + .getWaitingTime())); + atts.addAttribute("", "", "JoinElement", "CDATA", (m_WF_Node + .getJoinElement() != null ? m_WF_Node.getJoinElement() : "")); + atts.addAttribute("", "", "SplitElement", "CDATA", (m_WF_Node + .getSplitElement() != null ? m_WF_Node.getSplitElement() : "")); + atts.addAttribute("", "", "WaitTime", "CDATA", ("" + m_WF_Node + .getWaitTime())); + atts.addAttribute("", "", "AttributeName", "CDATA", + (m_WF_Node.getAttributeName() != null ? m_WF_Node + .getAttributeName() : "")); + atts.addAttribute("", "", "AttributeValue", "CDATA", (m_WF_Node + .getAttributeValue() != null ? m_WF_Node.getAttributeValue() + : "")); + atts.addAttribute("", "", "DocAction", "CDATA", (m_WF_Node + .getDocAction() != null ? m_WF_Node.getDocAction() : "")); + atts.addAttribute("", "", "DynPriorityUnit", "CDATA", (m_WF_Node + .getDynPriorityUnit() != null ? m_WF_Node.getDynPriorityUnit() + : "")); + atts.addAttribute("", "", "DynPriorityChange", "CDATA", ("" + m_WF_Node + .getDynPriorityChange())); + + return atts; + } +} diff --git a/base/src/org/adempiere/pipo/handler/WorkflowNodeNextConditionElementHandler.java b/base/src/org/adempiere/pipo/handler/WorkflowNodeNextConditionElementHandler.java new file mode 100644 index 0000000000..343f0ec205 --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/WorkflowNodeNextConditionElementHandler.java @@ -0,0 +1,260 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.X_AD_WF_NextCondition; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.wf.MWFNextCondition; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +public class WorkflowNodeNextConditionElementHandler extends + AbstractElementHandler { + + public void startElement(Properties ctx, Element element) + throws SAXException { + Attributes atts = element.attributes; + String entitytype = atts.getValue("EntityType"); + log.info("entitytype " + atts.getValue("EntityType")); + + if (entitytype.equals("U") || entitytype.equals("D") + && getUpdateMode(ctx).equals("true")) { + log.info("entitytype is a U or D"); + + String workflowName = atts.getValue("ADWorkflowNameID"); + + int workflowId = get_IDWithColumn(ctx, "AD_Workflow", "name", + workflowName); + if (workflowId <= 0) { + element.defer = true; + return; + } + + String workflowNodeName = atts.getValue("ADWorkflowNodeNameID"); + String workflowNodeNextName = atts + .getValue("ADWorkflowNodeNextNameID"); + + StringBuffer sqlB = new StringBuffer( + "SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?"); + + int wfNodeId = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), + workflowId, workflowNodeName); + if (wfNodeId <= 0) { + element.defer = true; + return; + } + + int wfNodeNextId = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), + workflowId, workflowNodeNextName); + if (wfNodeNextId <= 0) { + element.defer = true; + return; + } + + sqlB = new StringBuffer( + "SELECT ad_wf_nodenext_id FROM AD_WF_NodeNext WHERE ad_wf_node_id =? and ad_wf_next_id =?"); + int wfNodeNextTablePKId = DB.getSQLValue(getTrxName(ctx), sqlB + .toString(), wfNodeId, wfNodeNextId); + + sqlB = new StringBuffer( + "SELECT ad_wf_nextcondition_id FROM AD_WF_NextCondition WHERE ad_wf_nodenext_id =?"); + int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), + wfNodeNextTablePKId); + + MWFNextCondition m_WFNodeNextCondition = new MWFNextCondition(ctx, + id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_WF_NextCondition", + m_WFNodeNextCondition); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + + sqlB = new StringBuffer( + "SELECT AD_Column.ad_column_id FROM AD_Column, AD_Table WHERE AD_Column.ad_table_id = AD_Table.ad_table_id and AD_Table.name = '" + + atts.getValue("ADTableNameID") + + "' and AD_Column.name = ?"); + // int columnId = + // DB.getSQLValue(m_trxName,sqlB.toString(),atts.getValue("ADTableNameID"), + // atts.getValue("ADColumnNameID")); + int columnId = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), + atts.getValue("ADColumnNameID")); + m_WFNodeNextCondition.setAD_Column_ID(columnId); + + m_WFNodeNextCondition.setAD_WF_NodeNext_ID(wfNodeNextTablePKId); + m_WFNodeNextCondition + .setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() + : true); + m_WFNodeNextCondition.setAD_WF_NodeNext_ID(wfNodeNextTablePKId); + m_WFNodeNextCondition.setSeqNo(Integer.valueOf(atts + .getValue("SeqNo"))); + m_WFNodeNextCondition.setEntityType(atts.getValue("EntityType")); + m_WFNodeNextCondition.setAndOr(atts.getValue("AndOr")); + m_WFNodeNextCondition.setOperation(atts.getValue("Operation")); + m_WFNodeNextCondition.setValue(atts.getValue("Value")); + m_WFNodeNextCondition.setValue2(atts.getValue("Value2")); + getDocumentAttributes(ctx).clear(); + log.info("about to execute m_WFNodeNextCondition.save"); + if (m_WFNodeNextCondition.save(getTrxName(ctx)) == true) { + log.info("m_WFNodeNextCondition save success"); + record_log( + ctx, + 1, + String.valueOf(m_WFNodeNextCondition.get_ID()), + "WFNextCondition", + m_WFNodeNextCondition.get_ID(), + AD_Backup_ID, + Object_Status, + "AD_WF_NextCondition", + get_IDWithColumn(ctx, "AD_WF_NextCondition", + "ad_wf_nextcondition_id", "AD_WF_NextCondition")); + } else { + log.info("m_WFNodeNextCondition save failure"); + record_log( + ctx, + 0, + String.valueOf(m_WFNodeNextCondition.get_ID()), + "WFNextCondition", + m_WFNodeNextCondition.get_ID(), + AD_Backup_ID, + Object_Status, + "AD_WF_NextCondition", + get_IDWithColumn(ctx, "AD_WF_NextCondition", + "ad_wf_nextcondition_id", "AD_WF_NextCondition")); + throw new POSaveFailedException("WorkflowNodeNextCondition"); + } + } else { + log.info("entitytype is not a U or D"); + + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int ad_wf_nodenextcondition_id = Env.getContextAsInt(ctx, + X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID); + X_AD_WF_NextCondition m_WF_NodeNextCondition = new X_AD_WF_NextCondition( + ctx, ad_wf_nodenextcondition_id, null); + AttributesImpl atts = new AttributesImpl(); + createWorkflowNodeNextConditionBinding(atts, m_WF_NodeNextCondition); + document.startElement("", "", "workflowNodeNextCondition", atts); + document.endElement("", "", "workflowNodeNextCondition"); + } + + private AttributesImpl createWorkflowNodeNextConditionBinding( + AttributesImpl atts, X_AD_WF_NextCondition m_WF_NodeNextCondition) { + String sql = null; + String name = null; + atts.clear(); + + if (m_WF_NodeNextCondition.getAD_WF_NodeNext_ID() > 0) { + // FIXME: it appears nodes point back to themselves + // so a group by is necessary + sql = "SELECT AD_Workflow.Name FROM AD_Workflow, AD_WF_Node, AD_WF_NodeNext WHERE AD_Workflow.AD_Workflow_ID = AD_WF_Node.AD_Workflow_ID and AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_Workflow.Name"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition + .getAD_WF_NodeNext_ID()); + atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name); + // FIXME: it appears nodes point back to themselves + // so a group by is necessary + sql = "SELECT AD_WF_Node.Name FROM AD_WF_Node, AD_WF_NodeNext WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_WF_Node.Name"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition + .getAD_WF_NodeNext_ID()); + atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA", name); + // FIXME: it appears nodes point back to themselves + // so a group by is necessary + sql = "SELECT AD_WF_Node.Name FROM AD_WF_Node, AD_WF_NodeNext, AD_WF_NextCondition WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Next_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_WF_Node.Name"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition + .getAD_WF_NodeNext_ID()); + // log.log(Level.INFO,"node next name: ", name); + atts + .addAttribute("", "", "ADWorkflowNodeNextNameID", "CDATA", + name); + } + + if (m_WF_NodeNextCondition.getAD_Column_ID() > 0) { + + sql = "SELECT AD_Table.TableName FROM AD_Table, AD_Column, AD_WF_NextCondition WHERE AD_Column.AD_Table_ID=AD_Table.AD_Table_ID and AD_Column.AD_Column_ID = ?"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition + .getAD_Column_ID()); + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + + sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition + .getAD_Column_ID()); + atts.addAttribute("", "", "ADColumnNameID", "CDATA", name); + } else { + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + atts.addAttribute("", "", "ADColumnNameID", "CDATA", ""); + } + + // FIXME: don't know if I need org_id or not + // sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?"; + // name = DB.getSQLValueString(null,sql,org_id); + // atts.addAttribute("","","orgname","CDATA",name); + + atts.addAttribute("", "", "isActive", "CDATA", (m_WF_NodeNextCondition + .isActive() == true ? "true" : "false")); + atts + .addAttribute( + "", + "", + "EntityType", + "CDATA", + (m_WF_NodeNextCondition.getEntityType() != null ? m_WF_NodeNextCondition + .getEntityType() + : "")); + atts.addAttribute("", "", "AndOr", "CDATA", (m_WF_NodeNextCondition + .getAndOr() != null ? m_WF_NodeNextCondition.getAndOr() : "")); + atts.addAttribute("", "", "Operation", "CDATA", (m_WF_NodeNextCondition + .getOperation() != null ? m_WF_NodeNextCondition.getOperation() + : "")); + atts.addAttribute("", "", "Value", "CDATA", (m_WF_NodeNextCondition + .getValue() != null ? m_WF_NodeNextCondition.getValue() : "")); + atts + .addAttribute( + "", + "", + "Value2", + "CDATA", + (m_WF_NodeNextCondition.getValue2() != null ? m_WF_NodeNextCondition + .getValue2() + : "")); + atts.addAttribute("", "", "SeqNo", "CDATA", (String + .valueOf(m_WF_NodeNextCondition.getSeqNo()) != null ? String + .valueOf(m_WF_NodeNextCondition.getSeqNo()) : "")); + + return atts; + } + +} diff --git a/base/src/org/adempiere/pipo/handler/WorkflowNodeNextElementHandler.java b/base/src/org/adempiere/pipo/handler/WorkflowNodeNextElementHandler.java new file mode 100644 index 0000000000..d7ed125f2c --- /dev/null +++ b/base/src/org/adempiere/pipo/handler/WorkflowNodeNextElementHandler.java @@ -0,0 +1,261 @@ +/****************************************************************************** + * 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.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.X_AD_WF_NextCondition; +import org.compiere.model.X_AD_WF_NodeNext; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.wf.MWFNodeNext; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +public class WorkflowNodeNextElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) throws SAXException { + Attributes atts = element.attributes; + String entitytype = atts.getValue("EntityType"); + log.info("entitytype "+atts.getValue("EntityType")); + + if (entitytype.equals("U") || entitytype.equals("D") && getUpdateMode(ctx).equals("true")) { + log.info("entitytype is a U or D"); + + + String workflowName = atts.getValue("ADWorkflowNameID"); + int workflowId = get_IDWithColumn(ctx, "AD_Workflow", "name", workflowName); + if (workflowId <= 0) { + element.defer = true; + return; + } + + String workflowNodeName = atts.getValue("ADWorkflowNodeNameID"); + String workflowNodeNextName = atts.getValue("ADWorkflowNodeNextNameID"); + + StringBuffer sqlB = new StringBuffer ("SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?"); + + int wfNodeId = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),workflowId,workflowNodeName); + if (wfNodeId <= 0) { + element.defer = true; + return; + } + + int wfNodeNextId = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),workflowId,workflowNodeNextName); + + sqlB = new StringBuffer ("SELECT ad_wf_nodenext_id FROM AD_WF_NodeNext WHERE ad_wf_node_id =? and ad_wf_next_id =?"); + + int id = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),wfNodeId,wfNodeNextId); + + MWFNodeNext m_WFNodeNext = new MWFNodeNext(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0){ + AD_Backup_ID = copyRecord(ctx, "AD_WF_NodeNext",m_WFNodeNext); + Object_Status = "Update"; + } + else{ + Object_Status = "New"; + AD_Backup_ID =0; + } + m_WFNodeNext.setAD_WF_Node_ID(wfNodeId); + m_WFNodeNext.setAD_WF_Next_ID(wfNodeNextId); + m_WFNodeNext.setEntityType(atts.getValue("EntityType")); + m_WFNodeNext.setSeqNo(Integer.valueOf(atts.getValue("SeqNo"))); + m_WFNodeNext.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true); + m_WFNodeNext.setIsStdUserWorkflow(atts.getValue("IsStdUserWorkflow") != null ? Boolean.valueOf(atts.getValue("IsStdUserWorkflow")).booleanValue():true); +// log.info("m_WFNodeNext.get_ID: " + String.valueOf(m_WFNodeNext.get_ID)); + getDocumentAttributes(ctx).clear(); + log.info("about to execute m_WFNodeNext.save"); + if (m_WFNodeNext.save(getTrxName(ctx)) == true){ + log.info("m_WFNodeNext save success"); + record_log (ctx, 1, String.valueOf(m_WFNodeNext.get_ID()),"WFNodeNext", m_WFNodeNext.get_ID(),AD_Backup_ID, Object_Status,"AD_WF_NodeNext",get_IDWithColumn(ctx, "AD_WF_NodeNext", "ad_wf_nodenext_id", "AD_WF_NodeNext")); + } + else{ + log.info("m_WFNodeNext save failure"); + record_log (ctx, 0, String.valueOf(m_WFNodeNext.get_ID()),"WFNode", m_WFNodeNext.get_ID(),AD_Backup_ID, Object_Status,"AD_WF_NodeNext",get_IDWithColumn(ctx, "AD_WF_NodeNext", "ad_wf_nodenext_id", "AD_WF_NodeNext")); + throw new POSaveFailedException("WorkflowNodeNext"); + } + } else { + log.info("entitytype is not a U or D"); + + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int ad_wf_nodenext_id = Env.getContextAsInt(ctx, X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID); + X_AD_WF_NodeNext m_WF_NodeNext = new X_AD_WF_NodeNext( + ctx, ad_wf_nodenext_id, null); + AttributesImpl atts = new AttributesImpl(); + createWorkflowNodeNextBinding(atts, m_WF_NodeNext); + document.startElement("", "", "workflowNodeNext", + atts); + document.endElement("", "", "workflowNodeNext"); + + } + + private AttributesImpl createWorkflowNodeNextBinding(AttributesImpl atts, + X_AD_WF_NodeNext m_WF_NodeNext) + // public AttributesImpl createwf_nodenextBinding( AttributesImpl atts, + // X_AD_WF_NodeNext m_WF_NodeNext, X_AD_WF_Node m_WF_Node) + { + String sql = null; + String name = null; + atts.clear(); + // log.log(Level.INFO,"m_WF_NodeNext.getAD_WF_Node_ID: ", + // m_WF_NodeNext.getAD_WF_Node_ID()); + // log.log(Level.INFO,"m_WF_NodeNext.getAD_WF_Next_ID: ", + // m_WF_NodeNext.getAD_WF_Next_ID()); + + if (m_WF_NodeNext.getAD_WF_Node_ID() > 0) { + sql = "SELECT AD_Workflow.Name FROM AD_Workflow, AD_WF_Node WHERE AD_Workflow.AD_Workflow_ID = AD_WF_Node.AD_Workflow_ID and AD_WF_Node.AD_WF_Node_ID =?"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNext + .getAD_WF_Node_ID()); + atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name); + sql = "SELECT Name FROM AD_WF_Node WHERE AD_WF_Node_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNext + .getAD_WF_Node_ID()); + atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA", name); + } + + if (m_WF_NodeNext.getAD_WF_Next_ID() > 0) { + sql = "SELECT Name FROM AD_WF_Node WHERE AD_WF_Node_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNext + .getAD_WF_Next_ID()); + // log.log(Level.INFO,"node next name: ", name); + atts + .addAttribute("", "", "ADWorkflowNodeNextNameID", "CDATA", + name); + } + + // FIXME: don't know if I need org_id or not + // sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?"; + // name = DB.getSQLValueString(null,sql,org_id); + // atts.addAttribute("","","orgname","CDATA",name); + + atts.addAttribute("", "", "isActive", "CDATA", (m_WF_NodeNext + .isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "EntityType", "CDATA", (m_WF_NodeNext + .getEntityType() != null ? m_WF_NodeNext.getEntityType() : "")); + atts.addAttribute("", "", "Description", "CDATA", + (m_WF_NodeNext.getDescription() != null ? m_WF_NodeNext + .getDescription() : "")); + atts.addAttribute("", "", "SeqNo", "CDATA", (String + .valueOf(m_WF_NodeNext.getSeqNo()) != null ? String + .valueOf(m_WF_NodeNext.getSeqNo()) : "")); + atts.addAttribute("", "", "IsStdUserWorkflow", "CDATA", (String + .valueOf(m_WF_NodeNext.isStdUserWorkflow()) != null ? String + .valueOf(m_WF_NodeNext.isStdUserWorkflow()) : "")); + + return atts; + } + + private AttributesImpl createWorkflowNodeNextConditionBinding( + AttributesImpl atts, X_AD_WF_NextCondition m_WF_NodeNextCondition) { + String sql = null; + String name = null; + atts.clear(); + + if (m_WF_NodeNextCondition.getAD_WF_NodeNext_ID() > 0) { + // FIXME: it appears nodes point back to themselves + // so a group by is necessary + sql = "SELECT AD_Workflow.Name FROM AD_Workflow, AD_WF_Node, AD_WF_NodeNext WHERE AD_Workflow.AD_Workflow_ID = AD_WF_Node.AD_Workflow_ID and AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_Workflow.Name"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition + .getAD_WF_NodeNext_ID()); + atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name); + // FIXME: it appears nodes point back to themselves + // so a group by is necessary + sql = "SELECT AD_WF_Node.Name FROM AD_WF_Node, AD_WF_NodeNext WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_WF_Node.Name"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition + .getAD_WF_NodeNext_ID()); + atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA", name); + // FIXME: it appears nodes point back to themselves + // so a group by is necessary + sql = "SELECT AD_WF_Node.Name FROM AD_WF_Node, AD_WF_NodeNext, AD_WF_NextCondition WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Next_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_WF_Node.Name"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition + .getAD_WF_NodeNext_ID()); + // log.log(Level.INFO,"node next name: ", name); + atts + .addAttribute("", "", "ADWorkflowNodeNextNameID", "CDATA", + name); + } + + if (m_WF_NodeNextCondition.getAD_Column_ID() > 0) { + + sql = "SELECT AD_Table.TableName FROM AD_Table, AD_Column, AD_WF_NextCondition WHERE AD_Column.AD_Table_ID=AD_Table.AD_Table_ID and AD_Column.AD_Column_ID = ?"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition + .getAD_Column_ID()); + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + + sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition + .getAD_Column_ID()); + atts.addAttribute("", "", "ADColumnNameID", "CDATA", name); + } else { + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + atts.addAttribute("", "", "ADColumnNameID", "CDATA", ""); + } + + // FIXME: don't know if I need org_id or not + // sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?"; + // name = DB.getSQLValueString(null,sql,org_id); + // atts.addAttribute("","","orgname","CDATA",name); + + atts.addAttribute("", "", "isActive", "CDATA", (m_WF_NodeNextCondition + .isActive() == true ? "true" : "false")); + atts + .addAttribute( + "", + "", + "EntityType", + "CDATA", + (m_WF_NodeNextCondition.getEntityType() != null ? m_WF_NodeNextCondition + .getEntityType() + : "")); + atts.addAttribute("", "", "AndOr", "CDATA", (m_WF_NodeNextCondition + .getAndOr() != null ? m_WF_NodeNextCondition.getAndOr() : "")); + atts.addAttribute("", "", "Operation", "CDATA", (m_WF_NodeNextCondition + .getOperation() != null ? m_WF_NodeNextCondition.getOperation() + : "")); + atts.addAttribute("", "", "Value", "CDATA", (m_WF_NodeNextCondition + .getValue() != null ? m_WF_NodeNextCondition.getValue() : "")); + atts + .addAttribute( + "", + "", + "Value2", + "CDATA", + (m_WF_NodeNextCondition.getValue2() != null ? m_WF_NodeNextCondition + .getValue2() + : "")); + atts.addAttribute("", "", "SeqNo", "CDATA", (String + .valueOf(m_WF_NodeNextCondition.getSeqNo()) != null ? String + .valueOf(m_WF_NodeNextCondition.getSeqNo()) : "")); + + return atts; + } +}