diff --git a/base/src/org/adempiere/pipo/AbstractElementHandler.java b/base/src/org/adempiere/pipo/AbstractElementHandler.java index c3e45ef329..40fd8fe9c6 100644 --- a/base/src/org/adempiere/pipo/AbstractElementHandler.java +++ b/base/src/org/adempiere/pipo/AbstractElementHandler.java @@ -106,26 +106,22 @@ public abstract class AbstractElementHandler implements ElementHandler { .append( "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," ) .append( " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" ) .append( "VALUES(" ) - .append( " ?") - .append( ", ?" ) - .append( ", ?" ) - .append( ", ?" ) - .append( ", ?" ) - .append( ", ?" ) - .append( ", ?" ) - .append( ", ?" ) - .append( ", ?" ) - .append( ", ?" ) - .append( ", ?" ) - .append( ", ?" ) - .append( ", ?" ) - .append( ", ?") + .append( " "+ Env.getAD_Client_ID(ctx) ) + .append( ", "+ Env.getAD_Org_ID(ctx) ) + .append( ", "+ Env.getAD_User_ID(ctx) ) + .append( ", "+ Env.getAD_User_ID(ctx) ) + .append( ", " + id ) + .append( ", " + getPackageImpId(ctx) ) + .append( ", '" + objectType ) + .append( "', '" + objectName ) + .append( "', '" + objectStatus ) + .append( "', 'Success'" ) + .append( ", "+objectID ) + .append( ", "+objectIDBackup ) + .append( ", '"+tableName ) + .append( "', "+AD_Table_ID ) .append(")"); - Object[] param = new Object[] { Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx), Env.getAD_User_ID(ctx), Env.getAD_User_ID(ctx), - id, getPackageImpId(ctx) , objectType, objectName, objectStatus, "Success", objectID, objectIDBackup, tableName, - AD_Table_ID - }; - int no = DB.executeUpdate (sqlB.toString(), param, true, getTrxName(ctx)); + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); if (no == -1) log.info("Insert to import detail failed"); diff --git a/base/src/org/adempiere/pipo/PackInHandler.java b/base/src/org/adempiere/pipo/PackInHandler.java index dc7cf59577..6b5e707517 100644 --- a/base/src/org/adempiere/pipo/PackInHandler.java +++ b/base/src/org/adempiere/pipo/PackInHandler.java @@ -1,850 +1,850 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * * - * Copyright (C) 2004 Marco LOMBARDO. lombardo@mayking.com * - * Contributor: Robert KLEIN. robeklein@hotmail.com * - * Contributor: Tim Heath * - * Contributor: Low Heng Sin hengsin@avantz.com * - *****************************************************************************/ - -package org.adempiere.pipo; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Stack; -import java.util.logging.Level; - -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.sax.SAXTransformerFactory; -import javax.xml.transform.sax.TransformerHandler; -import javax.xml.transform.stream.StreamResult; - -import org.adempiere.pipo.handler.AdElementHandler; -import org.adempiere.pipo.handler.CodeSnipitElementHandler; -import org.adempiere.pipo.handler.ColumnElementHandler; -import org.adempiere.pipo.handler.CommonTranslationHandler; -import org.adempiere.pipo.handler.DataElementHandler; -import org.adempiere.pipo.handler.DistFileElementHandler; -import org.adempiere.pipo.handler.DynValRuleElementHandler; -import org.adempiere.pipo.handler.FieldElementHandler; -import org.adempiere.pipo.handler.FieldGroupElementHandler; -import org.adempiere.pipo.handler.FormAccessElementHandler; -import org.adempiere.pipo.handler.FormElementHandler; -import org.adempiere.pipo.handler.ImpFormatElementHandler; -import org.adempiere.pipo.handler.ImpFormatRowElementHandler; -import org.adempiere.pipo.handler.MenuElementHandler; -import org.adempiere.pipo.handler.MessageElementHandler; -import org.adempiere.pipo.handler.OrgRoleElementHandler; -import org.adempiere.pipo.handler.PreferenceElementHandler; -import org.adempiere.pipo.handler.PrintFormatElementHandler; -import org.adempiere.pipo.handler.PrintFormatItemElementHandler; -import org.adempiere.pipo.handler.ProcessAccessElementHandler; -import org.adempiere.pipo.handler.ProcessElementHandler; -import org.adempiere.pipo.handler.ProcessParaElementHandler; -import org.adempiere.pipo.handler.ReferenceElementHandler; -import org.adempiere.pipo.handler.ReferenceListElementHandler; -import org.adempiere.pipo.handler.ReferenceTableElementHandler; -import org.adempiere.pipo.handler.ReportViewColElementHandler; -import org.adempiere.pipo.handler.ReportViewElementHandler; -import org.adempiere.pipo.handler.RoleElementHandler; -import org.adempiere.pipo.handler.SQLStatementElementHandler; -import org.adempiere.pipo.handler.TabElementHandler; -import org.adempiere.pipo.handler.TableElementHandler; -import org.adempiere.pipo.handler.TaskAccessElementHandler; -import org.adempiere.pipo.handler.TaskElementHandler; -import org.adempiere.pipo.handler.UserRoleElementHandler; -import org.adempiere.pipo.handler.WindowAccessElementHandler; -import org.adempiere.pipo.handler.WindowElementHandler; -import org.adempiere.pipo.handler.WorkflowAccessElementHandler; -import org.adempiere.pipo.handler.WorkflowElementHandler; -import org.adempiere.pipo.handler.WorkflowNodeElementHandler; -import org.adempiere.pipo.handler.WorkflowNodeNextConditionElementHandler; -import org.adempiere.pipo.handler.WorkflowNodeNextElementHandler; -import org.compiere.model.MSequence; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Trx; -import org.compiere.wf.MWFNode; -import org.compiere.wf.MWorkflow; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; -import org.xml.sax.helpers.DefaultHandler; - -/** - * SAX Handler for parsing XML description of the GUI. - * - * @author Marco LOMBARDO, lombardo@mayking.com - * @author Robert KLEIN, robeklein@hotmail - * - * Contributor: William G. Heath - Import of workflows and dynamic validations - */ -public class PackInHandler extends DefaultHandler { - - /** - * PackInHandler Handler - */ - public PackInHandler () { - setupHandlers(); - } // PackInHandler - - /** Set this if you want to update Dictionary */ - private String m_UpdateMode = "true"; - private String packageDirectory = null; - private String m_DatabaseType = "Oracle"; - private int m_AD_Client_ID = 0; - private int AD_Package_Imp_ID=0; - private int AD_Package_Imp_Inst_ID=0; - private CLogger log = CLogger.getCLogger(PackInHandler.class); - private OutputStream fw_document = null; - private TransformerHandler logDocument = null; - private StreamResult streamResult_document = null; - private SAXTransformerFactory tf_document = null; - private Transformer serializer_document = null; - private int Start_Doc = 0; - private String logDate = null; - private String PK_Status = "Installing"; - // transaction name - private String m_trxName = null; - private Properties m_ctx = null; - - private Maphandlers = null; - private List menus = new ArrayList(); - private List workflow = new ArrayList(); - private List nodes = new ArrayList(); - private List defer = new ArrayList(); - private Stack stack = new Stack(); - private PackIn packIn; - - private void init() throws SAXException { - if (packIn == null) - packIn = new PackIn(); - packageDirectory = PackIn.m_Package_Dir; - m_UpdateMode = PackIn.m_UpdateMode; - m_DatabaseType = PackIn.m_Database; - SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssZ"); - SimpleDateFormat formatter_log = new SimpleDateFormat("MM/dd/yy HH:mm:ss"); - Date today = new Date(); - String fileDate = formatter_file.format(today); - logDate = formatter_log.format(today); - - String file_document = packageDirectory+File.separator+"doc"+File.separator+"Importlog_"+fileDate+".xml"; - log.info("file_document="+file_document); - try { - fw_document = new FileOutputStream (file_document, false); - } catch (FileNotFoundException e1) { - log.warning ("Failed to create log file:"+e1); - } - streamResult_document = new StreamResult(fw_document); - tf_document = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - - try { - logDocument = tf_document.newTransformerHandler(); - } catch (TransformerConfigurationException e2) { - log.info ("startElement:"+e2); - } - serializer_document = logDocument.getTransformer(); - serializer_document.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); - serializer_document.setOutputProperty(OutputKeys.INDENT,"yes"); - logDocument.setResult(streamResult_document); - logDocument.startDocument(); - logDocument.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\""); - Properties tmp = new Properties(); - if (m_ctx != null) - tmp.putAll(m_ctx); - else - tmp.putAll(Env.getCtx()); - m_ctx = tmp; - if (m_trxName == null) - m_trxName = Trx.createTrxName("PackIn"); - - m_AD_Client_ID = Env.getContextAsInt(m_ctx, "AD_Client_ID"); - - Start_Doc=1; - } - - private void setupHandlers() { - DataElementHandler dataHandler = new DataElementHandler(); - handlers = new HashMap(); - handlers.put("menu", new MenuElementHandler()); - handlers.put("adempieredata", dataHandler); - handlers.put("data", dataHandler); - handlers.put("dtable", dataHandler); - handlers.put("drow", dataHandler); - handlers.put("dcolumn", dataHandler); - handlers.put("window", new WindowElementHandler()); - handlers.put("windowaccess", new WindowAccessElementHandler()); - handlers.put("preference", new PreferenceElementHandler()); - handlers.put("tab", new TabElementHandler()); - handlers.put("field", new FieldElementHandler()); - handlers.put("process", new ProcessElementHandler()); - handlers.put("processpara", new ProcessParaElementHandler()); - handlers.put("processaccess", new ProcessAccessElementHandler()); - handlers.put("message", new MessageElementHandler()); - handlers.put("dynvalrule", new DynValRuleElementHandler()); - handlers.put("workflow", new WorkflowElementHandler()); - handlers.put("workflowNode", new WorkflowNodeElementHandler()); - handlers.put("workflowNodeNext", new WorkflowNodeNextElementHandler()); - handlers.put("workflowNodeNextCondition", new WorkflowNodeNextConditionElementHandler()); - handlers.put("workflowaccess", new WorkflowAccessElementHandler()); - handlers.put("table", new TableElementHandler()); - handlers.put("column", new ColumnElementHandler()); - handlers.put("role", new RoleElementHandler()); - handlers.put("userrole", new UserRoleElementHandler()); - handlers.put("orgrole", new OrgRoleElementHandler()); - handlers.put("form", new FormElementHandler()); - handlers.put("formaccess", new FormAccessElementHandler()); - handlers.put("task", new TaskElementHandler()); - handlers.put("taskaccess", new TaskAccessElementHandler()); - handlers.put("impformat", new ImpFormatElementHandler()); - handlers.put("impformatrow", new ImpFormatRowElementHandler()); - handlers.put("codesnipit", new CodeSnipitElementHandler()); - handlers.put("distfile", new DistFileElementHandler()); - handlers.put("reportview", new ReportViewElementHandler()); - handlers.put("reportviewcol", new ReportViewColElementHandler()); - handlers.put("printformat", new PrintFormatElementHandler()); - handlers.put("printformatitem", new PrintFormatItemElementHandler()); - handlers.put("SQLStatement", new SQLStatementElementHandler()); - handlers.put("reference", new ReferenceElementHandler()); - handlers.put("referencelist", new ReferenceListElementHandler()); - handlers.put("referencetable", new ReferenceTableElementHandler()); - handlers.put("fieldgroup", new FieldGroupElementHandler()); - handlers.put("element", new AdElementHandler()); - handlers.put("trl", new CommonTranslationHandler()); - } - - /** - * Receive notification of the start of an element. - * - * @param uri namespace - * @param localName simple name - * @param qName qualified name - * @param atts attributes - * @throws org.xml.sax.SAXException - */ - public void startElement (String uri, String localName, String qName, Attributes atts) - throws org.xml.sax.SAXException { - - // Create the package log - if (Start_Doc==0){ - init(); - } - // Check namespace. - String elementValue = null; - if ("".equals (uri)) - elementValue = qName; - else - elementValue = uri + localName; - - // adempiereAD. - if (elementValue.equals("adempiereAD")) { - log.info("adempiereAD updateMode="+m_UpdateMode); - //Start package log - AttributesImpl attsOut = new AttributesImpl(); - logDocument.startElement("","","adempiereDocument",attsOut); - logDocument.startElement("","","header",attsOut); - logDocument.characters((atts.getValue("Name")+" Install Log").toCharArray(),0,(atts.getValue("Name")+" Install Log").length()); - logDocument.endElement("","","header"); - logDocument.startElement("","","H3",attsOut); - logDocument.characters(("Package Name:" ).toCharArray(),0,("Package Name:" ).length()); - logDocument.endElement("","","H3"); - logDocument.startElement("","","packagename4log",attsOut); - logDocument.characters(atts.getValue("Name").toCharArray(),0,atts.getValue("Name").length()); - logDocument.endElement("","","packagename4log"); - logDocument.startElement("","","H3",attsOut); - logDocument.characters(("Version:" ).toCharArray(),0,("Version:" ).length()); - logDocument.endElement("","","H3"); - logDocument.startElement("","","Version",attsOut); - logDocument.characters(atts.getValue("Version").toCharArray(),0,atts.getValue("Version").length()); - logDocument.endElement("","","Version"); - logDocument.startElement("","","H3",attsOut); - logDocument.characters(("Package Install Date:" ).toCharArray(),0,("Package Install Date:" ).length()); - logDocument.endElement("","","H3"); - logDocument.startElement("","","installDate",attsOut); - logDocument.characters(logDate.toCharArray(),0,logDate.length()); - logDocument.endElement("","","installDate"); - logDocument.startElement("","","H3",attsOut); - logDocument.characters(("Min. Compiere Version:" ).toCharArray(),0,("Min. Compiere Version:" ).length()); - logDocument.endElement("","","H3"); - logDocument.startElement("","","CompVer",attsOut); - logDocument.characters(atts.getValue("CompVer").toCharArray(),0,atts.getValue("CompVer").length()); - logDocument.endElement("","","CompVer"); - logDocument.startElement("","","H3",attsOut); - logDocument.characters(("Min. Database Date:" ).toCharArray(),0,("Min. Database Date:" ).length()); - logDocument.endElement("","","H3"); - logDocument.startElement("","","DataBase",attsOut); - logDocument.characters(atts.getValue("DataBase").toCharArray(),0,atts.getValue("DataBase").length()); - logDocument.endElement("","","DataBase"); - - createImp_Sum_table ("AD_Package_Imp_Backup"); - createImp_Sum_table ("AD_Package_Imp"); - createImp_Sum_table ("AD_Package_Imp_Inst"); - createImp_Sum_table ("AD_Package_Imp_Detail"); - - // Update Summary Package History Table - String sql2 = "SELECT AD_PACKAGE_IMP_INST_ID FROM AD_PACKAGE_IMP_INST WHERE NAME =" - + "'" + atts.getValue("Name") - + "' AND PK_VERSION ='" + atts.getValue("Version") + "'"; - int PK_preInstalled = DB.getSQLValue(m_trxName,sql2); - - AD_Package_Imp_ID = DB.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp", null); - - StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp") - .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) - .append( "AD_PACKAGE_IMP_ID, RELEASENO, PK_VERSION, VERSION " ) - .append( ", DESCRIPTION, NAME, CREATOR" ) - .append( ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" ) - .append( "VALUES(" ) - .append( " "+ Env.getAD_Client_ID(m_ctx) ) - .append( ", "+ Env.getAD_Org_ID(m_ctx) ) - .append( ", "+ Env.getAD_User_ID(m_ctx) ) - .append( ", "+ Env.getAD_User_ID(m_ctx) ) - .append( ", " + AD_Package_Imp_ID ) - .append( ", '" + atts.getValue("CompVer") ) - .append( "', '" + atts.getValue("Version") ) - .append( "', '" + atts.getValue("DataBase") ) - .append( "', '" + atts.getValue("Description").replaceAll("'","''")) - .append( "', '" + atts.getValue("Name") ) - .append( "', '" + atts.getValue("creator") ) - .append( "', '" + atts.getValue("creatorcontact") ) - .append( "', '" + atts.getValue("createddate") ) - .append( "', '" + atts.getValue("updateddate") ) - .append( "', '" + PK_Status ) - .append( "')" ); - Env.getAD_User_ID(m_ctx); - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to Package import failed"); - - if ( PK_preInstalled == -1){ - AD_Package_Imp_Inst_ID = DB.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Inst", null); - - //Insert Package into package install log - sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Inst") - .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) - .append( "AD_PACKAGE_IMP_INST_ID, RELEASENO, PK_VERSION, VERSION " ) - .append( ", DESCRIPTION, NAME, CREATOR" ) - .append( ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" ) - .append( "VALUES(" ) - .append( " "+ Env.getAD_Client_ID(m_ctx) ) - .append( ", "+ Env.getAD_Org_ID(m_ctx) ) - .append( ", "+ Env.getAD_User_ID(m_ctx) ) - .append( ", "+ Env.getAD_User_ID(m_ctx) ) - .append( ", " + AD_Package_Imp_Inst_ID ) - .append( ", '" + atts.getValue("CompVer") ) - .append( "', '" + atts.getValue("Version") ) - .append( "', '" + atts.getValue("DataBase") ) - .append( "', '" + atts.getValue("Description").replaceAll("'","''")) - .append( "', '" + atts.getValue("Name") ) - .append( "', '" + atts.getValue("creator") ) - .append( "', '" + atts.getValue("creatorcontact") ) - .append( "', '" + atts.getValue("createddate") ) - .append( "', '" + atts.getValue("updateddate") ) - .append( "', '" + PK_Status ) - .append( "')" ); - - Env.getAD_User_ID(m_ctx); - no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to Package List import failed"); - } - else{ - //Update package list with package status - AD_Package_Imp_Inst_ID = PK_preInstalled; - sqlB = new StringBuffer ("UPDATE AD_Package_Imp_Inst " - + "SET PK_Status = '" + PK_Status - + "' WHERE AD_Package_Imp_Inst_ID = "+AD_Package_Imp_Inst_ID); - no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to package summary failed"); - } - Env.setContext(m_ctx, "AD_Package_Imp_ID", AD_Package_Imp_ID); - Env.setContext(m_ctx, "UpdateMode", m_UpdateMode); - Env.setContext(m_ctx, "TrxName", m_trxName); - Env.setContext(m_ctx, "PackageDirectory", packageDirectory); - m_ctx.put("LogDocument", logDocument); - m_ctx.put("PackInProcess", packIn); - } - else if (elementValue.equals("menu")) { - //defer - Element e = new Element(uri, localName, qName, new AttributesImpl(atts)); - if (stack.size() > 0) - e.parent = stack.peek(); - stack.push(e); - menus.add(e); - } - else { - Element e = new Element(uri, localName, qName, new AttributesImpl(atts)); - if (stack.size() > 0) - e.parent = stack.peek(); - stack.push(e); - if (elementValue.equals("workflow")) - { - workflow.add(e); - } - - if (elementValue.equals("workflowNode")) - { - nodes.add(e); - } - - - ElementHandler handler = handlers.get(elementValue); - if (handler != null) - handler.startElement(m_ctx, e); - if (e.defer) { - defer.add(new DeferEntry(e, true)); - } - } - } // startElement - - /** - * Check if Package History Table exists in database. If not create - * - * @param tablename - * - */ - public void createImp_Sum_table (String tablename){ - // Check if table exists. - - Connection conn = DB.getConnectionRW(); - DatabaseMetaData dbm; - try { - dbm = conn.getMetaData(); - // check if table is there - ResultSet tables = null; - if (m_DatabaseType.equals("Oracle")) - tables = dbm.getTables(null, null, tablename.toUpperCase(), null ); - else if (m_DatabaseType.equals("PostgreSQL")) - tables = dbm.getTables(null, null, tablename.toLowerCase(), null ); - - if (tables.next()) { - log.info ("Table Found"); - } - else { - if (tablename.equals("AD_Package_Imp")){ - StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") - .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) - .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) - .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) - .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) - .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "CREATEDBY NUMBER(10) NOT NULL, " ) - .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) - .append( "NAME NVARCHAR2(60) NOT NULL, " ) - .append( "PK_STATUS NVARCHAR2(22), " ) - .append( "RELEASENO NVARCHAR2(20), " ) - .append( "PK_VERSION NVARCHAR2(20), " ) - .append( "VERSION NVARCHAR2(20), " ) - .append( "DESCRIPTION NVARCHAR2(1000) NOT NULL, " ) - .append( "EMAIL NVARCHAR2(60), " ) - .append( "PROCESSED CHAR(1) DEFAULT 'N', " ) - .append( "PROCESSING CHAR(1) DEFAULT 'N', " ) - .append( "CREATOR VARCHAR2(60 ), " ) - .append( "CREATORCONTACT VARCHAR2(255), " ) - .append( " CREATEDDATE VARCHAR2(25), " ) - .append( "UPDATEDDATE VARCHAR2(25), " ) - .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); - - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_UPDATABLE, null); - pstmt.executeUpdate(); - MSequence.createTableSequence (m_ctx, "AD_Package_Imp", m_trxName); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("createImp_Sum_table:"+e); - } - } - if (tablename.equals("AD_Package_Imp_Inst")){ - StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") - .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) - .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) - .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) - .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) - .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "CREATEDBY NUMBER(10) NOT NULL, " ) - .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) - .append( "NAME NVARCHAR2(60) NOT NULL, " ) - .append( "PK_STATUS NVARCHAR2(22), " ) - .append( "RELEASENO NVARCHAR2(20), " ) - .append( "PK_VERSION NVARCHAR2(20), " ) - .append( "VERSION NVARCHAR2(20), " ) - .append( "DESCRIPTION NVARCHAR2(1000) NOT NULL, " ) - .append( "EMAIL NVARCHAR2(60), " ) - .append( "PROCESSED CHAR(1) DEFAULT 'N', " ) - .append( "PROCESSING CHAR(1) DEFAULT 'N', " ) - .append( "CREATOR VARCHAR2(60 ), " ) - .append( "CREATORCONTACT VARCHAR2(255), " ) - .append( " CREATEDDATE VARCHAR2(25), " ) - .append( "UPDATEDDATE VARCHAR2(25), " ) - .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); - - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_UPDATABLE, null); - pstmt.executeUpdate(); - MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Inst", m_trxName); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("createImp_Sum_table:"+e); - } - } - if (tablename.equals("AD_Package_Imp_Detail")){ - StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") - .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) - .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) - .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) - .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) - .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "CREATEDBY NUMBER(10) NOT NULL, " ) - .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) - .append( "NAME NVARCHAR2(60), " ) - .append( "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " ) - .append( "AD_ORIGINAL_ID Number(10) NOT NULL, " ) - .append( "AD_BACKUP_ID Number(10), " ) - .append( "ACTION NVARCHAR2(20), " ) - .append( "SUCCESS NVARCHAR2(20), " ) - .append( "TYPE NVARCHAR2(60), " ) - .append( "TABLENAME NVARCHAR2(60), " ) - .append( "AD_TABLE_ID NUMBER(10), " ) - .append( "UNINSTALL CHAR(1), " ) - .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); - - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_UPDATABLE, null); - pstmt.executeUpdate(); - MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Detail", m_trxName); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("createImp_Sum_table:"+e); - } - } - if (tablename.equals("AD_Package_Imp_Backup")){ - StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") - .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) - .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) - .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) - .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) - .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "CREATEDBY NUMBER(10) NOT NULL, " ) - .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) - .append( "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " ) - .append( "AD_PACKAGE_IMP_DETAIL_ID Number(10) NOT NULL, " ) - .append( "AD_TABLE_ID NUMBER(10), " ) - .append( "AD_COLUMN_ID NUMBER(10), " ) - .append( "AD_REFERENCE_ID NUMBER(10), " ) - .append( "AD_PACKAGE_IMP_BCK_DIR NVARCHAR2(255), " ) - .append( "AD_PACKAGE_IMP_ORG_DIR NVARCHAR2(255), " ) - .append( "COLVALUE NVARCHAR2(2000), " ) - .append( "UNINSTALL CHAR(1), " ) - .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); - - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_UPDATABLE, null); - pstmt.executeUpdate(); - MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Backup", m_trxName); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("createImp_Sum_table:"+e); - } - } - } - - tables.close(); - } - - catch (SQLException e) { - log.info ("createImp_Sum_table:"+e); - } - - finally - { - if( conn != null ) - { - try - { - conn.close(); - } - catch( Exception e ){} - } - } - } - - /** - * Receive notification of the end of an element. - * @param uri namespace - * @param localName simple name - * @param qName qualified name - * @throws SAXException - */ - public void endElement (String uri, String localName, String qName) throws SAXException { - // Check namespace. - String elementValue = null; - if ("".equals (uri)) - elementValue = qName; - else - elementValue = uri + localName; - - if (elementValue.equals("adempiereAD")){ - processDeferElements(); - processMenuElements(); - if (!PK_Status.equals("Completed with errors")) - PK_Status = "Completed successfully"; - - //Update package history log with package status - StringBuffer sqlB = new StringBuffer ("UPDATE AD_Package_Imp " - + "SET PK_Status = '" + PK_Status - + "' WHERE AD_Package_Imp_ID = " + AD_Package_Imp_ID); - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to package summary failed"); - - //Update package list with package status - sqlB = new StringBuffer ("UPDATE AD_Package_Imp_Inst " - + "SET PK_Status = '" + PK_Status - + "' WHERE AD_Package_Imp_Inst_ID = " + AD_Package_Imp_Inst_ID); - no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to package list failed"); - - if(workflow.size() > 0) - { - for (Element e : workflow) - { - Attributes atts = e.attributes; - String workflowName = atts.getValue("Name"); - MWorkflow wf = null; - - int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name", workflowName ,m_AD_Client_ID , m_trxName); - if(workflow_id > 0) - { - wf = new MWorkflow(m_ctx, workflow_id , m_trxName); - int node_id = 0; - - String name = atts.getValue("ADWorkflowNodeNameID"); - if (name != null && name.trim().length() > 0) - { - MWFNode[] nodes = wf.getNodes(false, m_AD_Client_ID); - - for (MWFNode node : nodes) - { - if (node.getName().trim().equals(name.trim())) - { - node_id = node.getAD_WF_Node_ID(); - wf.setAD_WF_Node_ID(node_id); - if (!wf.save()) - System.out.println("Can not save Start Node "+ name +"to Workflow " + workflowName + " do not exist "); - break; - } - } - - if(node_id == 0) - System.out.println("Unresolved: Start Node to Workflow " + workflowName + " do not exist "); - else - break; - } - - } - } - } - - if(nodes.size() > 0) - { - for (Element e : nodes) - { - Attributes atts = e.attributes; - String nodeName = atts.getValue("Name"); - MWFNode node = null; - int id = IDFinder.get_IDWithColumn("AD_WF_Node", "Name", nodeName , m_AD_Client_ID , m_trxName); - if(id > 0) - { - node = new MWFNode(m_ctx, id , m_trxName); - String workflowNodeName = atts.getValue("WorkflowNameID").trim(); - if (workflowNodeName != null && workflowNodeName.trim().length() > 0) - { - int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name",workflowNodeName, m_AD_Client_ID, m_trxName); - if (workflow_id > 0) - { - node.setWorkflow_ID(workflow_id); - if(!node.save()) - { - System.out.println("can not save Workflow " + workflowNodeName ); - } - } - else - System.out.println("Unresolved: Workflow " + workflowNodeName + " do not exist "); - } - - } - } - } - - logDocument.endElement("","","adempiereDocument"); - logDocument.endDocument(); - try { - fw_document.close(); - } - catch (Exception e) - {} - - //reset - setupHandlers(); - } else { - Element e = stack.pop(); - if (e.defer) { - defer.add(new DeferEntry(e, false)); - } else { - ElementHandler handler = handlers.get(elementValue); - if (handler != null) - handler.endElement(m_ctx, e); - if (e.defer || e.deferEnd) - defer.add(new DeferEntry(e, false)); - else if (!e.skip) { - if (log.isLoggable(Level.INFO)) - log.info("Processed: " + e.getElementValue() + " - " + e.attributes.getValue(0)); - } - } - } - - - - } // endElement - - private void processMenuElements() throws SAXException { - ElementHandler handler = handlers.get("menu"); - if (menus.size() > 0 && handler != null) { - for (Element e : menus) { - handler.startElement(m_ctx, e); - handler.endElement(m_ctx, e); - } - } - } - - private void processDeferElements() throws SAXException { - if (defer.isEmpty()) return; - - do { - int startSize = defer.size(); - List tmp = new ArrayList(defer); - defer.clear(); - for (DeferEntry d : tmp) { - if (d.startElement) { - d.element.defer = false; - d.element.unresolved = ""; - d.element.pass++; - } else { - if (d.element.deferEnd) { - d.element.deferEnd = false; - d.element.unresolved = ""; - } - } - if (log.isLoggable(Level.INFO)) { - log.info("Processeing Defer Element: " + d.element.getElementValue() + " - " - + d.element.attributes.getValue(0)); - } - ElementHandler handler = handlers.get(d.element.getElementValue()); - if (handler != null) { - if (d.startElement) - handler.startElement(m_ctx, d.element); - else - handler.endElement(m_ctx, d.element); - } - if (d.element.defer) - defer.add(d); - else if (!d.startElement) { - if (d.element.deferEnd) - defer.add(d); - else { - if (log.isLoggable(Level.INFO)) - log.info("Imported Defer Element: " + d.element.getElementValue() + " - " - + d.element.attributes.getValue(0)); - } - } - } - int endSize = defer.size(); - if (startSize == endSize) break; - } while (defer.size() > 0); - - if (defer.size() > 0) { - int count = 0; - for (DeferEntry d : defer) { - if (!d.startElement) { - count++; - if (log.isLoggable(Level.SEVERE)) - log.severe("Unresolved: " + d.element.getElementValue() + " - " + d.element.attributes.getValue(0) + ", " + d.element.unresolved); - } - } - //throw new RuntimeException("Failed to resolve dependency for " + count + " elements."); //commented by Joyce (12 Nov 2008) - //System.err.println("Failed to resolve dependency for " + count + " elements."); - } - } - - // globalqss - add support for trx in 3.1.2 - public void set_TrxName(String trxName) { - m_trxName = trxName; - } - - // globalqss - add support for trx in 3.1.2 - public void setCtx(Properties ctx) { - m_ctx = ctx; - } - - class DeferEntry { - Element element; - boolean startElement = false; - - DeferEntry(Element e, boolean b) { - element = e; - startElement = b; - } - } - - /** - * @param packIn - */ - public void setProcess(PackIn packIn) { - this.packIn = packIn; - } -} // PackInHandler +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * * + * Copyright (C) 2004 Marco LOMBARDO. lombardo@mayking.com * + * Contributor: Robert KLEIN. robeklein@hotmail.com * + * Contributor: Tim Heath * + * Contributor: Low Heng Sin hengsin@avantz.com * + *****************************************************************************/ + +package org.adempiere.pipo; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Stack; +import java.util.logging.Level; + +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.sax.TransformerHandler; +import javax.xml.transform.stream.StreamResult; + +import org.adempiere.pipo.handler.AdElementHandler; +import org.adempiere.pipo.handler.CodeSnipitElementHandler; +import org.adempiere.pipo.handler.ColumnElementHandler; +import org.adempiere.pipo.handler.CommonTranslationHandler; +import org.adempiere.pipo.handler.DataElementHandler; +import org.adempiere.pipo.handler.DistFileElementHandler; +import org.adempiere.pipo.handler.DynValRuleElementHandler; +import org.adempiere.pipo.handler.FieldElementHandler; +import org.adempiere.pipo.handler.FieldGroupElementHandler; +import org.adempiere.pipo.handler.FormAccessElementHandler; +import org.adempiere.pipo.handler.FormElementHandler; +import org.adempiere.pipo.handler.ImpFormatElementHandler; +import org.adempiere.pipo.handler.ImpFormatRowElementHandler; +import org.adempiere.pipo.handler.MenuElementHandler; +import org.adempiere.pipo.handler.MessageElementHandler; +import org.adempiere.pipo.handler.OrgRoleElementHandler; +import org.adempiere.pipo.handler.PreferenceElementHandler; +import org.adempiere.pipo.handler.PrintFormatElementHandler; +import org.adempiere.pipo.handler.PrintFormatItemElementHandler; +import org.adempiere.pipo.handler.ProcessAccessElementHandler; +import org.adempiere.pipo.handler.ProcessElementHandler; +import org.adempiere.pipo.handler.ProcessParaElementHandler; +import org.adempiere.pipo.handler.ReferenceElementHandler; +import org.adempiere.pipo.handler.ReferenceListElementHandler; +import org.adempiere.pipo.handler.ReferenceTableElementHandler; +import org.adempiere.pipo.handler.ReportViewColElementHandler; +import org.adempiere.pipo.handler.ReportViewElementHandler; +import org.adempiere.pipo.handler.RoleElementHandler; +import org.adempiere.pipo.handler.SQLStatementElementHandler; +import org.adempiere.pipo.handler.TabElementHandler; +import org.adempiere.pipo.handler.TableElementHandler; +import org.adempiere.pipo.handler.TaskAccessElementHandler; +import org.adempiere.pipo.handler.TaskElementHandler; +import org.adempiere.pipo.handler.UserRoleElementHandler; +import org.adempiere.pipo.handler.WindowAccessElementHandler; +import org.adempiere.pipo.handler.WindowElementHandler; +import org.adempiere.pipo.handler.WorkflowAccessElementHandler; +import org.adempiere.pipo.handler.WorkflowElementHandler; +import org.adempiere.pipo.handler.WorkflowNodeElementHandler; +import org.adempiere.pipo.handler.WorkflowNodeNextConditionElementHandler; +import org.adempiere.pipo.handler.WorkflowNodeNextElementHandler; +import org.compiere.model.MSequence; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.util.Trx; +import org.compiere.wf.MWFNode; +import org.compiere.wf.MWorkflow; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; +import org.xml.sax.helpers.DefaultHandler; + +/** + * SAX Handler for parsing XML description of the GUI. + * + * @author Marco LOMBARDO, lombardo@mayking.com + * @author Robert KLEIN, robeklein@hotmail + * + * Contributor: William G. Heath - Import of workflows and dynamic validations + */ +public class PackInHandler extends DefaultHandler { + + /** + * PackInHandler Handler + */ + public PackInHandler () { + setupHandlers(); + } // PackInHandler + + /** Set this if you want to update Dictionary */ + private String m_UpdateMode = "true"; + private String packageDirectory = null; + private String m_DatabaseType = "Oracle"; + private int m_AD_Client_ID = 0; + private int AD_Package_Imp_ID=0; + private int AD_Package_Imp_Inst_ID=0; + private CLogger log = CLogger.getCLogger(PackInHandler.class); + private OutputStream fw_document = null; + private TransformerHandler logDocument = null; + private StreamResult streamResult_document = null; + private SAXTransformerFactory tf_document = null; + private Transformer serializer_document = null; + private int Start_Doc = 0; + private String logDate = null; + private String PK_Status = "Installing"; + // transaction name + private String m_trxName = null; + private Properties m_ctx = null; + + private Maphandlers = null; + private List menus = new ArrayList(); + private List workflow = new ArrayList(); + private List nodes = new ArrayList(); + private List defer = new ArrayList(); + private Stack stack = new Stack(); + private PackIn packIn; + + private void init() throws SAXException { + if (packIn == null) + packIn = new PackIn(); + packageDirectory = PackIn.m_Package_Dir; + m_UpdateMode = PackIn.m_UpdateMode; + m_DatabaseType = PackIn.m_Database; + SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssZ"); + SimpleDateFormat formatter_log = new SimpleDateFormat("MM/dd/yy HH:mm:ss"); + Date today = new Date(); + String fileDate = formatter_file.format(today); + logDate = formatter_log.format(today); + + String file_document = packageDirectory+File.separator+"doc"+File.separator+"Importlog_"+fileDate+".xml"; + log.info("file_document="+file_document); + try { + fw_document = new FileOutputStream (file_document, false); + } catch (FileNotFoundException e1) { + log.warning ("Failed to create log file:"+e1); + } + streamResult_document = new StreamResult(fw_document); + tf_document = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); + + try { + logDocument = tf_document.newTransformerHandler(); + } catch (TransformerConfigurationException e2) { + log.info ("startElement:"+e2); + } + serializer_document = logDocument.getTransformer(); + serializer_document.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); + serializer_document.setOutputProperty(OutputKeys.INDENT,"yes"); + logDocument.setResult(streamResult_document); + logDocument.startDocument(); + logDocument.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\""); + Properties tmp = new Properties(); + if (m_ctx != null) + tmp.putAll(m_ctx); + else + tmp.putAll(Env.getCtx()); + m_ctx = tmp; + if (m_trxName == null) + m_trxName = Trx.createTrxName("PackIn"); + + m_AD_Client_ID = Env.getContextAsInt(m_ctx, "AD_Client_ID"); + + Start_Doc=1; + } + + private void setupHandlers() { + DataElementHandler dataHandler = new DataElementHandler(); + handlers = new HashMap(); + handlers.put("menu", new MenuElementHandler()); + handlers.put("adempieredata", dataHandler); + handlers.put("data", dataHandler); + handlers.put("dtable", dataHandler); + handlers.put("drow", dataHandler); + handlers.put("dcolumn", dataHandler); + handlers.put("window", new WindowElementHandler()); + handlers.put("windowaccess", new WindowAccessElementHandler()); + handlers.put("preference", new PreferenceElementHandler()); + handlers.put("tab", new TabElementHandler()); + handlers.put("field", new FieldElementHandler()); + handlers.put("process", new ProcessElementHandler()); + handlers.put("processpara", new ProcessParaElementHandler()); + handlers.put("processaccess", new ProcessAccessElementHandler()); + handlers.put("message", new MessageElementHandler()); + handlers.put("dynvalrule", new DynValRuleElementHandler()); + handlers.put("workflow", new WorkflowElementHandler()); + handlers.put("workflowNode", new WorkflowNodeElementHandler()); + handlers.put("workflowNodeNext", new WorkflowNodeNextElementHandler()); + handlers.put("workflowNodeNextCondition", new WorkflowNodeNextConditionElementHandler()); + handlers.put("workflowaccess", new WorkflowAccessElementHandler()); + handlers.put("table", new TableElementHandler()); + handlers.put("column", new ColumnElementHandler()); + handlers.put("role", new RoleElementHandler()); + handlers.put("userrole", new UserRoleElementHandler()); + handlers.put("orgrole", new OrgRoleElementHandler()); + handlers.put("form", new FormElementHandler()); + handlers.put("formaccess", new FormAccessElementHandler()); + handlers.put("task", new TaskElementHandler()); + handlers.put("taskaccess", new TaskAccessElementHandler()); + handlers.put("impformat", new ImpFormatElementHandler()); + handlers.put("impformatrow", new ImpFormatRowElementHandler()); + handlers.put("codesnipit", new CodeSnipitElementHandler()); + handlers.put("distfile", new DistFileElementHandler()); + handlers.put("reportview", new ReportViewElementHandler()); + handlers.put("reportviewcol", new ReportViewColElementHandler()); + handlers.put("printformat", new PrintFormatElementHandler()); + handlers.put("printformatitem", new PrintFormatItemElementHandler()); + handlers.put("SQLStatement", new SQLStatementElementHandler()); + handlers.put("reference", new ReferenceElementHandler()); + handlers.put("referencelist", new ReferenceListElementHandler()); + handlers.put("referencetable", new ReferenceTableElementHandler()); + handlers.put("fieldgroup", new FieldGroupElementHandler()); + handlers.put("element", new AdElementHandler()); + handlers.put("trl", new CommonTranslationHandler()); + } + + /** + * Receive notification of the start of an element. + * + * @param uri namespace + * @param localName simple name + * @param qName qualified name + * @param atts attributes + * @throws org.xml.sax.SAXException + */ + public void startElement (String uri, String localName, String qName, Attributes atts) + throws org.xml.sax.SAXException { + + // Create the package log + if (Start_Doc==0){ + init(); + } + // Check namespace. + String elementValue = null; + if ("".equals (uri)) + elementValue = qName; + else + elementValue = uri + localName; + + // adempiereAD. + if (elementValue.equals("adempiereAD")) { + log.info("adempiereAD updateMode="+m_UpdateMode); + //Start package log + AttributesImpl attsOut = new AttributesImpl(); + logDocument.startElement("","","adempiereDocument",attsOut); + logDocument.startElement("","","header",attsOut); + logDocument.characters((atts.getValue("Name")+" Install Log").toCharArray(),0,(atts.getValue("Name")+" Install Log").length()); + logDocument.endElement("","","header"); + logDocument.startElement("","","H3",attsOut); + logDocument.characters(("Package Name:" ).toCharArray(),0,("Package Name:" ).length()); + logDocument.endElement("","","H3"); + logDocument.startElement("","","packagename4log",attsOut); + logDocument.characters(atts.getValue("Name").toCharArray(),0,atts.getValue("Name").length()); + logDocument.endElement("","","packagename4log"); + logDocument.startElement("","","H3",attsOut); + logDocument.characters(("Version:" ).toCharArray(),0,("Version:" ).length()); + logDocument.endElement("","","H3"); + logDocument.startElement("","","Version",attsOut); + logDocument.characters(atts.getValue("Version").toCharArray(),0,atts.getValue("Version").length()); + logDocument.endElement("","","Version"); + logDocument.startElement("","","H3",attsOut); + logDocument.characters(("Package Install Date:" ).toCharArray(),0,("Package Install Date:" ).length()); + logDocument.endElement("","","H3"); + logDocument.startElement("","","installDate",attsOut); + logDocument.characters(logDate.toCharArray(),0,logDate.length()); + logDocument.endElement("","","installDate"); + logDocument.startElement("","","H3",attsOut); + logDocument.characters(("Min. Compiere Version:" ).toCharArray(),0,("Min. Compiere Version:" ).length()); + logDocument.endElement("","","H3"); + logDocument.startElement("","","CompVer",attsOut); + logDocument.characters(atts.getValue("CompVer").toCharArray(),0,atts.getValue("CompVer").length()); + logDocument.endElement("","","CompVer"); + logDocument.startElement("","","H3",attsOut); + logDocument.characters(("Min. Database Date:" ).toCharArray(),0,("Min. Database Date:" ).length()); + logDocument.endElement("","","H3"); + logDocument.startElement("","","DataBase",attsOut); + logDocument.characters(atts.getValue("DataBase").toCharArray(),0,atts.getValue("DataBase").length()); + logDocument.endElement("","","DataBase"); + + createImp_Sum_table ("AD_Package_Imp_Backup"); + createImp_Sum_table ("AD_Package_Imp"); + createImp_Sum_table ("AD_Package_Imp_Inst"); + createImp_Sum_table ("AD_Package_Imp_Detail"); + + // Update Summary Package History Table + String sql2 = "SELECT AD_PACKAGE_IMP_INST_ID FROM AD_PACKAGE_IMP_INST WHERE NAME =" + + "'" + atts.getValue("Name") + + "' AND PK_VERSION ='" + atts.getValue("Version") + "'"; + int PK_preInstalled = DB.getSQLValue(m_trxName,sql2); + + AD_Package_Imp_ID = DB.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp", null); + + StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp") + .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_PACKAGE_IMP_ID, RELEASENO, PK_VERSION, VERSION " ) + .append( ", DESCRIPTION, NAME, CREATOR" ) + .append( ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" ) + .append( "VALUES(" ) + .append( " "+ Env.getAD_Client_ID(m_ctx) ) + .append( ", "+ Env.getAD_Org_ID(m_ctx) ) + .append( ", "+ Env.getAD_User_ID(m_ctx) ) + .append( ", "+ Env.getAD_User_ID(m_ctx) ) + .append( ", " + AD_Package_Imp_ID ) + .append( ", '" + atts.getValue("CompVer") ) + .append( "', '" + atts.getValue("Version") ) + .append( "', '" + atts.getValue("DataBase") ) + .append( "', '" + atts.getValue("Description").replaceAll("'","''")) + .append( "', '" + atts.getValue("Name") ) + .append( "', '" + atts.getValue("creator") ) + .append( "', '" + atts.getValue("creatorcontact") ) + .append( "', '" + atts.getValue("createddate") ) + .append( "', '" + atts.getValue("updateddate") ) + .append( "', '" + PK_Status ) + .append( "')" ); + Env.getAD_User_ID(m_ctx); + int no = DB.executeUpdate (sqlB.toString(), m_trxName); + if (no == -1) + log.info("Insert to Package import failed"); + + if ( PK_preInstalled == -1){ + AD_Package_Imp_Inst_ID = DB.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Inst", null); + + //Insert Package into package install log + sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Inst") + .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_PACKAGE_IMP_INST_ID, RELEASENO, PK_VERSION, VERSION " ) + .append( ", DESCRIPTION, NAME, CREATOR" ) + .append( ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" ) + .append( "VALUES(" ) + .append( " "+ Env.getAD_Client_ID(m_ctx) ) + .append( ", "+ Env.getAD_Org_ID(m_ctx) ) + .append( ", "+ Env.getAD_User_ID(m_ctx) ) + .append( ", "+ Env.getAD_User_ID(m_ctx) ) + .append( ", " + AD_Package_Imp_Inst_ID ) + .append( ", '" + atts.getValue("CompVer") ) + .append( "', '" + atts.getValue("Version") ) + .append( "', '" + atts.getValue("DataBase") ) + .append( "', '" + atts.getValue("Description").replaceAll("'","''")) + .append( "', '" + atts.getValue("Name") ) + .append( "', '" + atts.getValue("creator") ) + .append( "', '" + atts.getValue("creatorcontact") ) + .append( "', '" + atts.getValue("createddate") ) + .append( "', '" + atts.getValue("updateddate") ) + .append( "', '" + PK_Status ) + .append( "')" ); + + Env.getAD_User_ID(m_ctx); + no = DB.executeUpdate (sqlB.toString(), m_trxName); + if (no == -1) + log.info("Insert to Package List import failed"); + } + else{ + //Update package list with package status + AD_Package_Imp_Inst_ID = PK_preInstalled; + sqlB = new StringBuffer ("UPDATE AD_Package_Imp_Inst " + + "SET PK_Status = '" + PK_Status + + "' WHERE AD_Package_Imp_Inst_ID = "+AD_Package_Imp_Inst_ID); + no = DB.executeUpdate (sqlB.toString(), m_trxName); + if (no == -1) + log.info("Update to package summary failed"); + } + Env.setContext(m_ctx, "AD_Package_Imp_ID", AD_Package_Imp_ID); + Env.setContext(m_ctx, "UpdateMode", m_UpdateMode); + Env.setContext(m_ctx, "TrxName", m_trxName); + Env.setContext(m_ctx, "PackageDirectory", packageDirectory); + m_ctx.put("LogDocument", logDocument); + m_ctx.put("PackInProcess", packIn); + } + else if (elementValue.equals("menu")) { + //defer + Element e = new Element(uri, localName, qName, new AttributesImpl(atts)); + if (stack.size() > 0) + e.parent = stack.peek(); + stack.push(e); + menus.add(e); + } + else { + Element e = new Element(uri, localName, qName, new AttributesImpl(atts)); + if (stack.size() > 0) + e.parent = stack.peek(); + stack.push(e); + if (elementValue.equals("workflow")) + { + workflow.add(e); + } + + if (elementValue.equals("workflowNode")) + { + nodes.add(e); + } + + + ElementHandler handler = handlers.get(elementValue); + if (handler != null) + handler.startElement(m_ctx, e); + if (e.defer) { + defer.add(new DeferEntry(e, true)); + } + } + } // startElement + + /** + * Check if Package History Table exists in database. If not create + * + * @param tablename + * + */ + public void createImp_Sum_table (String tablename){ + // Check if table exists. + + Connection conn = DB.getConnectionRW(); + DatabaseMetaData dbm; + try { + dbm = conn.getMetaData(); + // check if table is there + ResultSet tables = null; + if (m_DatabaseType.equals("Oracle")) + tables = dbm.getTables(null, null, tablename.toUpperCase(), null ); + else if (m_DatabaseType.equals("PostgreSQL")) + tables = dbm.getTables(null, null, tablename.toLowerCase(), null ); + + if (tables.next()) { + log.info ("Table Found"); + } + else { + if (tablename.equals("AD_Package_Imp")){ + StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") + .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) + .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) + .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) + .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) + .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "CREATEDBY NUMBER(10) NOT NULL, " ) + .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) + .append( "NAME NVARCHAR2(60) NOT NULL, " ) + .append( "PK_STATUS NVARCHAR2(22), " ) + .append( "RELEASENO NVARCHAR2(20), " ) + .append( "PK_VERSION NVARCHAR2(20), " ) + .append( "VERSION NVARCHAR2(20), " ) + .append( "DESCRIPTION NVARCHAR2(1000) NOT NULL, " ) + .append( "EMAIL NVARCHAR2(60), " ) + .append( "PROCESSED CHAR(1) DEFAULT 'N', " ) + .append( "PROCESSING CHAR(1) DEFAULT 'N', " ) + .append( "CREATOR VARCHAR2(60 ), " ) + .append( "CREATORCONTACT VARCHAR2(255), " ) + .append( " CREATEDDATE VARCHAR2(25), " ) + .append( "UPDATEDDATE VARCHAR2(25), " ) + .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE, null); + pstmt.executeUpdate(); + MSequence.createTableSequence (m_ctx, "AD_Package_Imp", m_trxName); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("createImp_Sum_table:"+e); + } + } + if (tablename.equals("AD_Package_Imp_Inst")){ + StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") + .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) + .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) + .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) + .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) + .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "CREATEDBY NUMBER(10) NOT NULL, " ) + .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) + .append( "NAME NVARCHAR2(60) NOT NULL, " ) + .append( "PK_STATUS NVARCHAR2(22), " ) + .append( "RELEASENO NVARCHAR2(20), " ) + .append( "PK_VERSION NVARCHAR2(20), " ) + .append( "VERSION NVARCHAR2(20), " ) + .append( "DESCRIPTION NVARCHAR2(1000) NOT NULL, " ) + .append( "EMAIL NVARCHAR2(60), " ) + .append( "PROCESSED CHAR(1) DEFAULT 'N', " ) + .append( "PROCESSING CHAR(1) DEFAULT 'N', " ) + .append( "CREATOR VARCHAR2(60 ), " ) + .append( "CREATORCONTACT VARCHAR2(255), " ) + .append( " CREATEDDATE VARCHAR2(25), " ) + .append( "UPDATEDDATE VARCHAR2(25), " ) + .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE, null); + pstmt.executeUpdate(); + MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Inst", m_trxName); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("createImp_Sum_table:"+e); + } + } + if (tablename.equals("AD_Package_Imp_Detail")){ + StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") + .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) + .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) + .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) + .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) + .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "CREATEDBY NUMBER(10) NOT NULL, " ) + .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) + .append( "NAME NVARCHAR2(60), " ) + .append( "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " ) + .append( "AD_ORIGINAL_ID Number(10) NOT NULL, " ) + .append( "AD_BACKUP_ID Number(10), " ) + .append( "ACTION NVARCHAR2(20), " ) + .append( "SUCCESS NVARCHAR2(20), " ) + .append( "TYPE NVARCHAR2(60), " ) + .append( "TABLENAME NVARCHAR2(60), " ) + .append( "AD_TABLE_ID NUMBER(10), " ) + .append( "UNINSTALL CHAR(1), " ) + .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE, null); + pstmt.executeUpdate(); + MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Detail", m_trxName); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("createImp_Sum_table:"+e); + } + } + if (tablename.equals("AD_Package_Imp_Backup")){ + StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") + .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) + .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) + .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) + .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) + .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "CREATEDBY NUMBER(10) NOT NULL, " ) + .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) + .append( "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " ) + .append( "AD_PACKAGE_IMP_DETAIL_ID Number(10) NOT NULL, " ) + .append( "AD_TABLE_ID NUMBER(10), " ) + .append( "AD_COLUMN_ID NUMBER(10), " ) + .append( "AD_REFERENCE_ID NUMBER(10), " ) + .append( "AD_PACKAGE_IMP_BCK_DIR NVARCHAR2(255), " ) + .append( "AD_PACKAGE_IMP_ORG_DIR NVARCHAR2(255), " ) + .append( "COLVALUE NVARCHAR2(2000), " ) + .append( "UNINSTALL CHAR(1), " ) + .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE, null); + pstmt.executeUpdate(); + MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Backup", m_trxName); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("createImp_Sum_table:"+e); + } + } + } + + tables.close(); + } + + catch (SQLException e) { + log.info ("createImp_Sum_table:"+e); + } + + finally + { + if( conn != null ) + { + try + { + conn.close(); + } + catch( Exception e ){} + } + } + } + + /** + * Receive notification of the end of an element. + * @param uri namespace + * @param localName simple name + * @param qName qualified name + * @throws SAXException + */ + public void endElement (String uri, String localName, String qName) throws SAXException { + // Check namespace. + String elementValue = null; + if ("".equals (uri)) + elementValue = qName; + else + elementValue = uri + localName; + + if (elementValue.equals("adempiereAD")){ + processDeferElements(); + processMenuElements(); + if (!PK_Status.equals("Completed with errors")) + PK_Status = "Completed successfully"; + + //Update package history log with package status + StringBuffer sqlB = new StringBuffer ("UPDATE AD_Package_Imp " + + "SET PK_Status = '" + PK_Status + + "' WHERE AD_Package_Imp_ID = " + AD_Package_Imp_ID); + int no = DB.executeUpdate (sqlB.toString(), m_trxName); + if (no == -1) + log.info("Update to package summary failed"); + + //Update package list with package status + sqlB = new StringBuffer ("UPDATE AD_Package_Imp_Inst " + + "SET PK_Status = '" + PK_Status + + "' WHERE AD_Package_Imp_Inst_ID = " + AD_Package_Imp_Inst_ID); + no = DB.executeUpdate (sqlB.toString(), m_trxName); + if (no == -1) + log.info("Update to package list failed"); + + if(workflow.size() > 0) + { + for (Element e : workflow) + { + Attributes atts = e.attributes; + String workflowName = atts.getValue("Name"); + MWorkflow wf = null; + + int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name", workflowName ,m_AD_Client_ID , m_trxName); + if(workflow_id > 0) + { + wf = new MWorkflow(m_ctx, workflow_id , m_trxName); + int node_id = 0; + + String name = atts.getValue("ADWorkflowNodeNameID"); + if (name != null && name.trim().length() > 0) + { + MWFNode[] nodes = wf.getNodes(false, m_AD_Client_ID); + + for (MWFNode node : nodes) + { + if (node.getName().trim().equals(name.trim())) + { + node_id = node.getAD_WF_Node_ID(); + wf.setAD_WF_Node_ID(node_id); + if (!wf.save()) + System.out.println("Can not save Start Node "+ name +"to Workflow " + workflowName + " do not exist "); + break; + } + } + + if(node_id == 0) + System.out.println("Unresolved: Start Node to Workflow " + workflowName + " do not exist "); + else + break; + } + + } + } + } + + if(nodes.size() > 0) + { + for (Element e : nodes) + { + Attributes atts = e.attributes; + String nodeName = atts.getValue("Name"); + MWFNode node = null; + int id = IDFinder.get_IDWithColumn("AD_WF_Node", "Name", nodeName , m_AD_Client_ID , m_trxName); + if(id > 0) + { + node = new MWFNode(m_ctx, id , m_trxName); + String workflowNodeName = atts.getValue("WorkflowNameID").trim(); + if (workflowNodeName != null && workflowNodeName.trim().length() > 0) + { + int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name",workflowNodeName, m_AD_Client_ID, m_trxName); + if (workflow_id > 0) + { + node.setWorkflow_ID(workflow_id); + if(!node.save()) + { + System.out.println("can not save Workflow " + workflowNodeName ); + } + } + else + System.out.println("Unresolved: Workflow " + workflowNodeName + " do not exist "); + } + + } + } + } + + logDocument.endElement("","","adempiereDocument"); + logDocument.endDocument(); + try { + fw_document.close(); + } + catch (Exception e) + {} + + //reset + setupHandlers(); + } else { + Element e = stack.pop(); + if (e.defer) { + defer.add(new DeferEntry(e, false)); + } else { + ElementHandler handler = handlers.get(elementValue); + if (handler != null) + handler.endElement(m_ctx, e); + if (e.defer || e.deferEnd) + defer.add(new DeferEntry(e, false)); + else if (!e.skip) { + if (log.isLoggable(Level.INFO)) + log.info("Processed: " + e.getElementValue() + " - " + e.attributes.getValue(0)); + } + } + } + + + + } // endElement + + private void processMenuElements() throws SAXException { + ElementHandler handler = handlers.get("menu"); + if (menus.size() > 0 && handler != null) { + for (Element e : menus) { + handler.startElement(m_ctx, e); + handler.endElement(m_ctx, e); + } + } + } + + private void processDeferElements() throws SAXException { + if (defer.isEmpty()) return; + + do { + int startSize = defer.size(); + List tmp = new ArrayList(defer); + defer.clear(); + for (DeferEntry d : tmp) { + if (d.startElement) { + d.element.defer = false; + d.element.unresolved = ""; + d.element.pass++; + } else { + if (d.element.deferEnd) { + d.element.deferEnd = false; + d.element.unresolved = ""; + } + } + if (log.isLoggable(Level.INFO)) { + log.info("Processeing Defer Element: " + d.element.getElementValue() + " - " + + d.element.attributes.getValue(0)); + } + ElementHandler handler = handlers.get(d.element.getElementValue()); + if (handler != null) { + if (d.startElement) + handler.startElement(m_ctx, d.element); + else + handler.endElement(m_ctx, d.element); + } + if (d.element.defer) + defer.add(d); + else if (!d.startElement) { + if (d.element.deferEnd) + defer.add(d); + else { + if (log.isLoggable(Level.INFO)) + log.info("Imported Defer Element: " + d.element.getElementValue() + " - " + + d.element.attributes.getValue(0)); + } + } + } + int endSize = defer.size(); + if (startSize == endSize) break; + } while (defer.size() > 0); + + if (defer.size() > 0) { + int count = 0; + for (DeferEntry d : defer) { + if (!d.startElement) { + count++; + if (log.isLoggable(Level.SEVERE)) + log.severe("Unresolved: " + d.element.getElementValue() + " - " + d.element.attributes.getValue(0) + ", " + d.element.unresolved); + } + } + throw new RuntimeException("Failed to resolve dependency for " + count + " elements."); + //System.err.println("Failed to resolve dependency for " + count + " elements."); + } + } + + // globalqss - add support for trx in 3.1.2 + public void set_TrxName(String trxName) { + m_trxName = trxName; + } + + // globalqss - add support for trx in 3.1.2 + public void setCtx(Properties ctx) { + m_ctx = ctx; + } + + class DeferEntry { + Element element; + boolean startElement = false; + + DeferEntry(Element e, boolean b) { + element = e; + startElement = b; + } + } + + /** + * @param packIn + */ + public void setProcess(PackIn packIn) { + this.packIn = packIn; + } +} // PackInHandler diff --git a/base/src/org/adempiere/pipo/handler/DataElementHandler.java b/base/src/org/adempiere/pipo/handler/DataElementHandler.java index 974d2d2e78..3b8158da21 100644 --- a/base/src/org/adempiere/pipo/handler/DataElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/DataElementHandler.java @@ -23,7 +23,8 @@ import java.sql.ResultSetMetaData; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; +import java.util.Iterator; import java.util.Properties; import java.util.logging.Level; @@ -38,7 +39,6 @@ import org.compiere.model.PO; import org.compiere.model.POInfo; import org.compiere.model.X_AD_Package_Exp_Detail; import org.compiere.util.DB; -import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -100,66 +100,14 @@ public class DataElementHandler extends AbstractElementHandler { public void startElement(Properties ctx, Element element) throws SAXException { String elementValue = element.getElementValue(); Attributes atts = element.attributes; - log.info(elementValue+" "+atts.getValue("name")); - + log.info(elementValue+" "+atts.getValue("name")); MTable table = MTable.get(ctx, d_tablename); - // use keyXname and lookupkeyXname if available - if (atts.getValue("key1name") != null && atts.getValue("key1name").trim().length() > 0) - { - String sql = "select * from "+d_tablename; - String whereand = " where"; - - Listparams = new ArrayList(); - int keyIndex = 1; - while (true) { - String currentKey = "key" + keyIndex + "name"; - if (atts.getValue(currentKey) != null && !atts.getValue(currentKey).equals("")) { - params.add(atts.getValue("lookup"+currentKey)); - sql = sql+whereand+" "+atts.getValue(currentKey)+"=?"; - whereand = " and"; - keyIndex++; - } else { - break; - } - } - - if (getClientId(ctx) > 0) { - sql = sql + whereand + " " + d_tablename + ".AD_Client_ID in (0, " + getClientId(ctx) + ")"; - sql = sql + " Order by " + d_tablename + ".AD_Client_ID Desc"; - } else { - sql = sql + whereand + " " + d_tablename + ".AD_Client_ID = 0"; - } - - // Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value - try { - PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx)); - for (int i = 0; i < params.size(); i++) { - pstmt.setString(i+1, params.get(i)); - } - - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) { - objectStatus = "Update"; - genericPO = table.getPO(rs, getTrxName(ctx)); - rs.close(); - pstmt.close(); - pstmt = null; - } - else { - genericPO = table.getPO(0, getTrxName(ctx)); - rs.close(); - pstmt.close(); - pstmt = null; - objectStatus = "New"; - } - } - catch (Exception e) { - log.log(Level.SEVERE, e.getLocalizedMessage(), e); - } - } else { - //fallback to name attribute - String nameAttribute = atts.getValue("name"); - int id = get_ID(ctx, d_tablename, nameAttribute); + + String d_rowname = atts.getValue("name"); + + // name can be null if there are keyXname attributes. + if (!d_rowname.equals("")){ + int id = get_ID(ctx, d_tablename, d_rowname); genericPO = table.getPO(id, getTrxName(ctx)); if (id > 0){ if (genericPO == null || genericPO.get_ID() != id) @@ -172,6 +120,66 @@ public class DataElementHandler extends AbstractElementHandler { AD_Backup_ID =0; } } + // keyXname and lookupkeyXname. + else { + String sql = "select * from "+d_tablename; + String whereand = " where"; + String CURRENT_KEY = "key1name"; + if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) { + sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY); + whereand = " and"; + } + CURRENT_KEY = "key2name"; + if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) { + sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY); + whereand = " and"; + } + if (whereand.equals(" where")) + log.warning("no name or keyXname attribute defined."); + // Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value + try { + PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) { + objectStatus = "Update"; + genericPO = table.getPO(rs, getTrxName(ctx)); + rs.close(); + pstmt.close(); + pstmt = null; + } + else { + rs.close(); + rs = null; + pstmt.close(); + pstmt = null; + objectStatus = "New"; + genericPO = table.getPO(0, getTrxName(ctx)); + // set keyXname. + CURRENT_KEY = "key1name"; + if (!atts.getValue(CURRENT_KEY).equals("")) { + String colName = atts.getValue(CURRENT_KEY); + String valueObject = atts.getValue("lookup"+CURRENT_KEY); + if (colName.endsWith("_ID") && valueObject.contains("SELECT")) + valueObject = DB.getSQLValueString(getTrxName(ctx), valueObject); + genericPO.set_ValueOfColumn(colName, valueObject); + } + CURRENT_KEY = "key2name"; + if (!atts.getValue(CURRENT_KEY).equals("")) { + String colName = atts.getValue(CURRENT_KEY); + String valueObject = atts.getValue("lookup"+CURRENT_KEY); + if (colName.endsWith("_ID") && valueObject.contains("SELECT")) + valueObject = DB.getSQLValueString(getTrxName(ctx), valueObject); + genericPO.set_ValueOfColumn(colName, valueObject); + } + } + + } + catch (Exception e) { + log.warning ("keyXname attribute. init from rs error."+e); + throw new SAXException(e.getMessage()); + } + } // for debug GenericPO. if (false) { @@ -184,7 +192,29 @@ public class DataElementHandler extends AbstractElementHandler { } // globalqss: set AD_Client_ID to the client setted in adempieredata if (getClientId(ctx) > 0 && genericPO.getAD_Client_ID() != getClientId(ctx)) - genericPO.set_ValueOfColumn("AD_Client_ID", getClientId(ctx)); + genericPO.set_ValueOfColumn("AD_Client_ID", getClientId(ctx)); + // if new. TODO: no defaults for keyXname. + if (!d_rowname.equals("") && ((Integer)(genericPO.get_Value(d_tablename+"_ID"))).intValue() == 0) { + log.info("new genericPO, table: "+d_tablename+" name:"+d_rowname); + genericPO.set_ValueOfColumn("Name", d_rowname); + // Set defaults. + //TODO: get defaults from configuration + HashMap defaults = new HashMap(); + HashMap thisDefault = (HashMap)defaults.get(d_tablename); + if (thisDefault != null) { + Iterator iter = thisDefault.values().iterator(); + ArrayList thisValue = null; + while (iter.hasNext()) { + thisValue = (ArrayList)iter.next(); + if (((String)(thisValue.get(2))).equals("String")) + genericPO.set_ValueOfColumn((String)thisValue.get(0), (String)thisValue.get(1)); + else if (((String)(thisValue.get(2))).equals("Integer")) + genericPO.set_ValueOfColumn((String)thisValue.get(0), Integer.valueOf((String)thisValue.get(1))); + else if (((String)(thisValue.get(2))).equals("Boolean")) + genericPO.set_ValueOfColumn((String)thisValue.get(0), new Boolean(((String)thisValue.get(1)).equals("true") ? true : false)); + } + } + } } public void endElement(Properties ctx, Element element) throws SAXException { @@ -215,10 +245,6 @@ public class DataElementHandler extends AbstractElementHandler { String columnName = atts.getValue("name"); int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename); int id =get_IDWithMasterAndColumn (ctx,"AD_Column", "ColumnName", columnName, "AD_Table", tableid); - if (id <= 0) { - log.log(Level.WARNING, "Column not found in AD_Column, TableName=" + d_tablename + " ColumnName=" + columnName); - return; - } StringBuffer sql = new StringBuffer ("SELECT IsUpdateable FROM AD_column WHERE AD_Column_ID = ?"); String isUpdateable = DB.getSQLValueString(getTrxName(ctx), sql.toString(),id); sql = new StringBuffer ("SELECT IsKey FROM AD_column WHERE AD_Column_ID = ?"); @@ -226,44 +252,37 @@ public class DataElementHandler extends AbstractElementHandler { if (("New".equals(objectStatus)) || (isKey.equals("N") && isUpdateable.equals("Y") && (!atts.getValue("name").equals("CreatedBy")||!atts.getValue("name").equals("UpdatedBy")))) { - String value = atts.getValue("value"); - if (value != null && !value.equals("null") && value.trim().length() > 0) { + 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") || atts.getValue("name").equals("AD_Language") || atts.getValue("name").equals("EntityType")) { - genericPO.set_ValueOfColumn(atts.getValue("name"), value); + genericPO.set_ValueOfColumn(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.set_ValueOfColumn(atts.getValue("name"), new BigDecimal(value)); + genericPO.set_ValueOfColumn(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.set_ValueOfColumn(atts.getValue("name"), Integer.valueOf(value)); + genericPO.set_ValueOfColumn(atts.getValue("name").toString(), Integer.valueOf(atts.getValue("value"))); } else if (atts.getValue("class").equals("Boolean")) { - genericPO.set_ValueOfColumn(atts.getValue("name"), new Boolean(value.equals("true") ? true : false)); + genericPO.set_ValueOfColumn(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.set_ValueOfColumn(atts.getValue("name"), Timestamp.valueOf(value)); + genericPO.set_ValueOfColumn(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.set_ValueOfColumn(atts.getValue("name"), new Integer(getIDbyName(ctx, m_tablename, atts.getValue("lookupname")))); - } else if ( atts.getValue("sql") != null && atts.getValue("sql").trim().length() > 0) { - String idSql = atts.getValue("sql"); - idSql = idSql.replace("@AD_Client_ID@", Integer.toString(getClientId(ctx))); - int result = DB.getSQLValue(getTrxName(ctx), idSql); - if (result >= 0) - genericPO.set_ValueOfColumn(atts.getValue("name"), result); } } } @@ -278,10 +297,6 @@ public class DataElementHandler extends AbstractElementHandler { } - /** - * @param ctx - * @param document - */ public void create(Properties ctx, TransformerHandler document) throws SAXException { String sql = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); @@ -302,53 +317,37 @@ public class DataElementHandler extends AbstractElementHandler { document.startElement("","","dtable",atts); while (rs.next()){ atts.clear(); - int keyIndex = 0; + 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 isIdentifier = 'Y' AND " + + "WHERE isKey = 'Y' AND " + "AD_Table_ID = ? AND " + "Upper(ColumnName)= '"+col_Name+"'"; String cName = DB.getSQLValueString(null,sql2,table_id); if (cName != null){ - if (cName.toUpperCase().equals(col_Name)){ - keyIndex++; - atts.addAttribute("","","key" + keyIndex + "name","CDATA",cName); - atts.addAttribute("","","lookupkey" + keyIndex + "name","CDATA",""+rs.getObject(col_Name)); + if (cName.toUpperCase().equals(col_Name) && key1 == 0 ){ + atts.addAttribute("","","key1name","CDATA",cName); + atts.addAttribute("","","lookupkey1name","CDATA",""+rs.getObject(col_Name)); + key1 = 1; } - } - } - - //fall back to Id - if (keyIndex == 0) { - for (i=1 ;i <= columns;i++){ - col_Name = meta.getColumnName(i).toUpperCase(); - if (col_Name.equals("NAME") && rs.getObject("name") != null) - nameatts = ""+rs.getObject("name"); - String sql2 = "SELECT ColumnName FROM AD_Column " - + "WHERE isKey = 'Y' AND " - + "AD_Table_ID = ? AND " - + "Upper(ColumnName)= '"+col_Name+"'"; - String cName = DB.getSQLValueString(null,sql2,table_id); - if (cName != null){ - if (cName.toUpperCase().equals(col_Name)){ - keyIndex++; - atts.addAttribute("","","key" + keyIndex + "name","CDATA",cName); - atts.addAttribute("","","lookupkey" + keyIndex + "name","CDATA",""+rs.getObject(col_Name)); - } + 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 ( keyIndex == 0 ){ + if ( key1 == 0 ){ atts.addAttribute("","","key1name","CDATA",""); atts.addAttribute("","","lookupkey1name","CDATA",""); - keyIndex++; + key1 = 1; } - if ( keyIndex == 1 ){ + if ( key1 == 1 ){ atts.addAttribute("","","key2name","CDATA",""); atts.addAttribute("","","lookupkey2name","CDATA",""); } @@ -356,12 +355,11 @@ public class DataElementHandler extends AbstractElementHandler { for (i=1 ;i <= columns;i++){ atts.clear(); col_Name = meta.getColumnName(i).toUpperCase(); - String sql2 = "Select A.ColumnName, B.Name, A.AD_Reference_ID, A.AD_Reference_Value_ID " + 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 " - + "AND A.ColumnName != 'AD_Client_ID' "; + + "A.AD_Reference_ID = B.AD_Reference_ID"; PreparedStatement pstmt = null; try { @@ -374,50 +372,11 @@ public class DataElementHandler extends AbstractElementHandler { atts.clear(); atts.addAttribute("","","name","CDATA", rs1.getString("ColumnName")); atts.addAttribute("","","class","CDATA", rs1.getString("Name")); + if (rs1.getString("Name").equals("Date")||rs1.getString("Name").equals("Date+Time")||rs1.getString("Name").equals("Time")) + atts.addAttribute("","","value","CDATA", "" + rs.getTimestamp(i)); + else + atts.addAttribute("","","value","CDATA", "" + rs.getObject(i)); - //rs1.getString("ColumnName") : NAME / VALUE - //rs1.getString("Name") : STRING - //rs1.getString("AD_Reference_ID") : number (table/table direct/ search) - //rs1.getString("AD_Reference_Value_ID") : number (null when type is table direct) - - if (rs1.getInt("AD_Reference_ID") == DisplayType.Table || rs1.getInt("AD_Reference_ID") == DisplayType.Search - || rs1.getInt("AD_Reference_ID") == DisplayType.TableDir ){ - String tableName = ""; - - if (rs1.getInt("AD_Reference_ID") == DisplayType.TableDir){ - //if rs1.getString("ColumnName") = C_EDIFORMAT_ID, tablename = C_EDIFORMAT - tableName = rs1.getString("ColumnName").substring(0,rs1.getString("ColumnName").length()-3); - }else{ - //ad_ref_table.ad_reference_id = ad_reference_value_id - int referenceId = rs1.getInt("AD_Reference_Value_ID"); - - if (referenceId != 0) - tableName = getTableNameFromReferenceId(referenceId); - else - tableName = rs1.getString("ColumnName").substring(0,rs1.getString("ColumnName").length()-3); - } - - if (rs.getObject(i) == null) - atts.addAttribute("","","value","CDATA", ""); - else{ - String insertSql = getSqlFromTableName(tableName,Integer.parseInt(rs.getObject(i).toString()),ctx); - - String parentSql = getParentSql(tableName,ctx,Integer.parseInt(rs.getObject(i).toString())); - if (!parentSql.equals("")) - insertSql = insertSql + parentSql; - - insertSql = insertSql + " Order By " + tableName + ".AD_Client_ID Desc "; - - atts.addAttribute("","","value","CDATA", ""); - atts.addAttribute("", "", "sql", "CDATA", insertSql); - } - - } else { - if (rs1.getString("Name").equals("Date")||rs1.getString("Name").equals("Date+Time")||rs1.getString("Name").equals("Time")) - atts.addAttribute("","","value","CDATA", "" + rs.getTimestamp(i)); - else - atts.addAttribute("","","value","CDATA", "" + rs.getObject(i)); - } if (!rs1.getString("ColumnName").equals("Created")&&!rs1.getString("ColumnName").equals("CreatedBy")&& !rs1.getString("ColumnName").equals("Updated")&&!rs1.getString("ColumnName").equals("UpdatedBy")){ document.startElement("","","dcolumn",atts); @@ -447,95 +406,5 @@ public class DataElementHandler extends AbstractElementHandler { document.endElement("","","data"); } - - private String getTableNameFromReferenceId(int referenceId){ - String tableName = ""; - String sql = " SELECT t.TableName FROM AD_Table T, AD_Ref_Table R " - +" WHERE T.AD_Table_ID=R.AD_Table_ID AND R.AD_Reference_ID=? "; - tableName= DB.getSQLValueString(null,sql,referenceId); - - return tableName; - } - - private String getSqlFromTableName(String tableName, int id, Properties ctx) throws Exception{ - String result = null; - - String sql = "SELECT count(a.ad_table_id) FROM ad_table a INNER JOIN ad_column b ON (a.ad_table_id = b.ad_table_id) " - + "AND a.tablename = '" + tableName + "' AND UPPER(b.columnname) = 'VALUE'"; - int count = DB.getSQLValue(null, sql); - - String insertSqlValue = count <= 0 - ? ( "SELECT Name FROM "+tableName+" WHERE "+tableName+"_ID=?" ) - : ( "SELECT Value FROM "+tableName+" WHERE "+tableName+"_ID=?" ); - PreparedStatement pstmt = null; - ResultSet rs = null; - - try{ - pstmt = DB.prepareStatement(insertSqlValue, getTrxName(ctx)); - pstmt.setInt(1, id); - rs = pstmt.executeQuery(); - if (rs.next()){ - - if (count <= 0) - result = "SELECT " +tableName+"_ID FROM "+tableName+" WHERE Name='"+rs.getString(1)+"'"; - else - result = "SELECT " +tableName+"_ID FROM "+tableName+" WHERE Value='"+rs.getString(1)+"'"; - result = result + " AND " + tableName + ".AD_Client_ID IN ( @AD_Client_ID@ , 0 )"; - } - - } catch (Exception e) { - log.log(Level.SEVERE, e.getLocalizedMessage(), e); - } finally { - DB.close(rs, pstmt); - } - - return result; - } - - private String getParentSql(String tableName, Properties ctx, int recordId) throws Exception{ - String parentSql = ""; - PreparedStatement pstmt = null; - ResultSet rs = null; - - try{ - String sql = "SELECT A.ColumnName, A.AD_Reference_ID, A.AD_Reference_Value_ID " - + "FROM AD_Column A, AD_Table T " - + "Where A.AD_TABLE_ID = T.AD_Table_ID AND A.IsParent = 'Y' " - + "AND UPPER(T.TableName)=? " - + "AND A.ColumnName != 'AD_Client_ID' "; - - pstmt = DB.prepareStatement(sql, getTrxName(ctx)); - pstmt.setString(1,tableName.toUpperCase()); - rs = pstmt.executeQuery(); - - while(rs.next()){ - if (rs.getInt("AD_Reference_ID") == DisplayType.Table || rs.getInt("AD_Reference_ID") == DisplayType.Search || rs.getInt("AD_Reference_ID") == DisplayType.TableDir){ - String parentTableName = ""; - - if (rs.getInt("AD_Reference_ID") == DisplayType.TableDir){ - //if rs1.getString("ColumnName") = C_EDIFORMAT_ID, tablename = C_EDIFORMAT - parentTableName = rs.getString("ColumnName").substring(0,rs.getString("ColumnName").length()-3); - }else{ - //ad_ref_table.ad_reference_id = ad_reference_value_id - int referenceId = rs.getInt("AD_Reference_Value_ID"); - parentTableName = getTableNameFromReferenceId(referenceId); - } - - String parentIdSql = "SELECT "+parentTableName+"_ID FROM "+tableName+" WHERE "+tableName+"_ID = "+recordId; - int parentRecordId = DB.getSQLValue(null, parentIdSql); - - parentSql = " AND "+rs.getString("ColumnName")+ " IN (" +getParentSql(parentTableName, ctx, parentRecordId)+")"; - parentSql = parentSql + " AND " + tableName + ".AD_Client_ID IN ( @AD_Client_ID@ , 0 )"; - } - } - } catch (Exception e) { - log.log(Level.SEVERE, e.getLocalizedMessage(), e); - } finally{ - DB.close(rs, pstmt); - } - - return parentSql; - } + } - - diff --git a/base/src/org/adempiere/pipo/handler/FieldElementHandler.java b/base/src/org/adempiere/pipo/handler/FieldElementHandler.java index 157948d8df..4fde3de301 100644 --- a/base/src/org/adempiere/pipo/handler/FieldElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/FieldElementHandler.java @@ -47,7 +47,6 @@ public class FieldElementHandler extends AbstractElementHandler { if (element.parent != null && element.parent.getElementValue().equals("tab") && element.parent.defer) { element.defer = true; - element.unresolved = element.parent.unresolved; return; } String name = atts.getValue("Name"); @@ -61,7 +60,6 @@ public class FieldElementHandler extends AbstractElementHandler { packIn.addTable(tableName, tableid); } if (tableid <= 0) { - element.unresolved = "AD_Table=" + tableName; element.defer = true; return; } @@ -69,7 +67,6 @@ public class FieldElementHandler extends AbstractElementHandler { .getValue("ADWindowNameID")); if (windowid <= 0) { element.defer = true; - element.unresolved = "AD_Window=" + atts.getValue("ADWindowNameID"); return; } int columnid = packIn.getColumnId(tableName, colname); @@ -81,7 +78,6 @@ public class FieldElementHandler extends AbstractElementHandler { } if (columnid <= 0) { element.defer = true; - element.unresolved = "AD_Column"+ colname; return; } int tabid = 0; @@ -176,7 +172,6 @@ public class FieldElementHandler extends AbstractElementHandler { } } else { element.defer = true; - element.unresolved = "AD_Tab=" + tabname; return; } } else { diff --git a/migration/353a-trunk/oracle/411-2Pack_1976008.sql b/migration/353a-trunk/oracle/411-2Pack_1976008.sql deleted file mode 100644 index 86887af649..0000000000 --- a/migration/353a-trunk/oracle/411-2Pack_1976008.sql +++ /dev/null @@ -1,30 +0,0 @@ --- Aug 6, 2008 10:39:44 AM SGT --- Packin to any client -UPDATE AD_Table SET AccessLevel='6',Updated=TO_DATE('2008-08-06 10:39:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50008 -; - --- Aug 6, 2008 10:39:57 AM SGT --- Packin to any client -UPDATE AD_Table SET AccessLevel='6',Updated=TO_DATE('2008-08-06 10:39:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50003 -; - --- Aug 6, 2008 10:40:31 AM SGT --- Packin to any client -DELETE FROM AD_Window_Access WHERE AD_Role_ID=102 -; - --- Aug 6, 2008 10:40:32 AM SGT --- Packin to any client -INSERT INTO AD_Window_Access (AD_Window_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT w.AD_Window_ID, 102,11,0,'Y', SysDate,100, SysDate,100,'Y' FROM AD_Window w INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID) INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) WHERE t.SeqNo=(SELECT MIN(SeqNo) FROM AD_Tab xt WHERE xt.AD_Window_ID=w.AD_Window_ID)AND tt.AccessLevel IN ('7','6','3','2','1') -; - --- Aug 6, 2008 10:40:32 AM SGT --- Packin to any client -DELETE FROM AD_Process_Access WHERE AD_Role_ID=102 -; - --- Aug 6, 2008 10:40:32 AM SGT --- Packin to any client -INSERT INTO AD_Process_Access (AD_Process_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT p.AD_Process_ID, 102,11,0,'Y', SysDate,100, SysDate,100,'Y' FROM AD_Process p WHERE AccessLevel IN ('7','6','3','2','1') -; - diff --git a/migration/353a-trunk/oracle/411-2Pack_1976008_reverted.sql b/migration/353a-trunk/oracle/411-2Pack_1976008_reverted.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/migration/353a-trunk/postgresql/411-2Pack_1976008.sql b/migration/353a-trunk/postgresql/411-2Pack_1976008.sql deleted file mode 100644 index 169a59058c..0000000000 --- a/migration/353a-trunk/postgresql/411-2Pack_1976008.sql +++ /dev/null @@ -1,30 +0,0 @@ --- Aug 6, 2008 10:39:44 AM SGT --- Packin to any client -UPDATE AD_Table SET AccessLevel='6',Updated=TO_TIMESTAMP('2008-08-06 10:39:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50008 -; - --- Aug 6, 2008 10:39:57 AM SGT --- Packin to any client -UPDATE AD_Table SET AccessLevel='6',Updated=TO_TIMESTAMP('2008-08-06 10:39:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50003 -; - --- Aug 6, 2008 10:40:32 AM SGT --- Packin to any client -DELETE FROM AD_Window_Access WHERE AD_Role_ID=102 -; - --- Aug 6, 2008 10:40:32 AM SGT --- Packin to any client -INSERT INTO AD_Window_Access (AD_Window_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT w.AD_Window_ID, 102,11,0,'Y', CURRENT_TIMESTAMP,100, CURRENT_TIMESTAMP,100,'Y' FROM AD_Window w INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID) INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) WHERE t.SeqNo=(SELECT MIN(SeqNo) FROM AD_Tab xt WHERE xt.AD_Window_ID=w.AD_Window_ID)AND tt.AccessLevel IN ('7','6','3','2','1') -; - --- Aug 6, 2008 10:40:32 AM SGT --- Packin to any client -DELETE FROM AD_Process_Access WHERE AD_Role_ID=102 -; - --- Aug 6, 2008 10:40:32 AM SGT --- Packin to any client -INSERT INTO AD_Process_Access (AD_Process_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT p.AD_Process_ID, 102,11,0,'Y', CURRENT_TIMESTAMP,100, CURRENT_TIMESTAMP,100,'Y' FROM AD_Process p WHERE AccessLevel IN ('7','6','3','2','1') -; - diff --git a/migration/353a-trunk/postgresql/411-2Pack_1976008_reverted.sql b/migration/353a-trunk/postgresql/411-2Pack_1976008_reverted.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/migration/processes_post_migration/postgresql/processes_post_migration.sql b/migration/processes_post_migration/postgresql/processes_post_migration.sql new file mode 100644 index 0000000000..1455fbee7c --- /dev/null +++ b/migration/processes_post_migration/postgresql/processes_post_migration.sql @@ -0,0 +1,1246 @@ +CREATE OR REPLACE FUNCTION add_missing_translations() RETURNS void as $func$ +DECLARE + ins VARCHAR (2000); + sel VARCHAR (2000); + inssel VARCHAR (4001); + table_id NUMERIC; + t RECORD; + c RECORD; +BEGIN + + FOR t IN (SELECT ad_table_id, + SUBSTR (tablename, 1, LENGTH (tablename) - 4) as tablename + FROM AD_TABLE + WHERE tablename LIKE '%_Trl' AND isactive = 'Y' + AND isview = 'N') + LOOP + ins := + 'INSERT INTO ' + || t.tablename + || '_TRL (' + || 'ad_language,ad_client_id,ad_org_id,created,createdby,updated,updatedby,isactive,istranslated,' + || t.tablename + || '_id'; + sel := + 'SELECT l.ad_language,t.ad_client_id,t.ad_org_id,t.created,t.createdby,t.updated,t.updatedby,t.isactive,''N'' as istranslated,' + || t.tablename + || '_id'; + + SELECT ad_table_id + INTO table_id + FROM AD_TABLE + WHERE tablename = t.tablename; + + FOR c IN (SELECT col.columnname + FROM AD_COLUMN col INNER JOIN AD_TABLE tab + ON (col.ad_table_id = tab.ad_table_id) + WHERE col.ad_table_id = table_id + AND col.istranslated = 'Y' + AND col.isactive = 'Y' + ORDER BY 1) + LOOP + ins := TRIM (ins) || ',' || TRIM (c.columnname); + sel := TRIM (sel) || ',t.' || TRIM (c.columnname); + END LOOP; + + ins := TRIM (ins) || ')'; + sel := + TRIM (sel) + || ' from ' + || t.tablename + || ' t, ad_language l WHERE l.issystemlanguage=''Y'' AND NOT EXISTS (SELECT 1 FROM ' + || t.tablename + || '_TRL b WHERE b.' + || t.tablename + || '_id=t.' + || t.tablename + || '_id AND b.AD_LANGUAGE=l.AD_LANGUAGE)'; + inssel := TRIM (ins) || ' ' || TRIM (sel); + + EXECUTE inssel; + END LOOP; + +END; +$func$ LANGUAGE plpgsql; + +select add_missing_translations(); + +commit; + +-- Synchronize Terminology + +/* +-- take account of the output for these two selects + +SELECT DISTINCT columnname, NAME, description, HELP, entitytype + FROM AD_COLUMN c + WHERE NOT EXISTS (SELECT 1 + FROM AD_ELEMENT e + WHERE UPPER (c.columnname) = UPPER (e.columnname)); + +SELECT DISTINCT columnname, NAME, description, HELP, entitytype + FROM AD_PROCESS_PARA p + WHERE NOT EXISTS (SELECT 1 + FROM AD_ELEMENT e + WHERE UPPER (p.columnname) = UPPER (e.columnname)); + +*/ +-- execute + +INSERT INTO AD_ELEMENT_TRL + (ad_element_id, AD_LANGUAGE, ad_client_id, ad_org_id, isactive, + created, createdby, updated, updatedby, NAME, printname, + description, HELP, istranslated) + SELECT m.ad_element_id, l.AD_LANGUAGE, m.ad_client_id, m.ad_org_id, + m.isactive, m.created, m.createdby, m.updated, m.updatedby, m.NAME, + m.printname, m.description, m.HELP, 'N' + FROM AD_ELEMENT m, AD_LANGUAGE l + WHERE l.isactive = 'Y' + AND l.issystemlanguage = 'Y' + AND ad_element_id || AD_LANGUAGE NOT IN ( + SELECT ad_element_id || AD_LANGUAGE + FROM AD_ELEMENT_TRL); + +UPDATE AD_COLUMN + SET ad_element_id = (SELECT ad_element_id + FROM AD_ELEMENT e + WHERE UPPER (AD_COLUMN.columnname) = UPPER (e.columnname)) + WHERE ad_element_id IS NULL; + +DELETE FROM AD_ELEMENT_TRL + WHERE ad_element_id IN ( + SELECT ad_element_id + FROM AD_ELEMENT e + WHERE NOT EXISTS ( + SELECT 1 + FROM AD_COLUMN c + WHERE UPPER (e.columnname) = + UPPER (c.columnname)) + AND NOT EXISTS ( + SELECT 1 + FROM AD_PROCESS_PARA p + WHERE UPPER (e.columnname) = + UPPER (p.columnname))); + +DELETE FROM AD_ELEMENT + WHERE NOT EXISTS (SELECT 1 + FROM AD_COLUMN c + WHERE UPPER (AD_ELEMENT.columnname) = UPPER (c.columnname)) + AND NOT EXISTS (SELECT 1 + FROM AD_PROCESS_PARA p + WHERE UPPER (AD_ELEMENT.columnname) = UPPER (p.columnname)); + +UPDATE AD_COLUMN + SET columnname = + (SELECT columnname + FROM AD_ELEMENT e + WHERE AD_COLUMN.ad_element_id = e.ad_element_id), + NAME = + (SELECT NAME + FROM AD_ELEMENT e + WHERE AD_COLUMN.ad_element_id = e.ad_element_id), + description = + (SELECT description + FROM AD_ELEMENT e + WHERE AD_COLUMN.ad_element_id = e.ad_element_id), + HELP = + (SELECT HELP + FROM AD_ELEMENT e + WHERE AD_COLUMN.ad_element_id = e.ad_element_id), + updated = current_timestamp + WHERE EXISTS ( + SELECT 1 + FROM AD_ELEMENT e + WHERE AD_COLUMN.ad_element_id = e.ad_element_id + AND ( AD_COLUMN.columnname <> e.columnname + OR AD_COLUMN.NAME <> e.NAME + OR COALESCE (AD_COLUMN.description, ' ') <> COALESCE (e.description, ' ') + OR COALESCE (AD_COLUMN.HELP, ' ') <> COALESCE (e.HELP, ' ') + )); + +UPDATE AD_FIELD + SET NAME = + (SELECT e.NAME + FROM AD_ELEMENT e, AD_COLUMN c + WHERE e.ad_element_id = c.ad_element_id + AND c.ad_column_id = AD_FIELD.ad_column_id), + description = + (SELECT e.description + FROM AD_ELEMENT e, AD_COLUMN c + WHERE e.ad_element_id = c.ad_element_id + AND c.ad_column_id = AD_FIELD.ad_column_id), + HELP = + (SELECT e.HELP + FROM AD_ELEMENT e, AD_COLUMN c + WHERE e.ad_element_id = c.ad_element_id + AND c.ad_column_id = AD_FIELD.ad_column_id), + updated = current_timestamp + WHERE AD_FIELD.iscentrallymaintained = 'Y' + AND AD_FIELD.isactive = 'Y' + AND EXISTS ( + SELECT 1 + FROM AD_ELEMENT e, AD_COLUMN c + WHERE AD_FIELD.ad_column_id = c.ad_column_id + AND c.ad_element_id = e.ad_element_id + AND c.ad_process_id IS NULL + AND ( AD_FIELD.NAME <> e.NAME + OR COALESCE (AD_FIELD.description, ' ') <> COALESCE (e.description, ' ') + OR COALESCE (AD_FIELD.HELP, ' ') <> COALESCE (e.HELP, ' ') + )); + +UPDATE AD_FIELD_TRL + SET NAME = + (SELECT e.NAME + FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f + WHERE e.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE + AND e.ad_element_id = c.ad_element_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id), + description = + (SELECT e.description + FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f + WHERE e.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE + AND e.ad_element_id = c.ad_element_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id), + HELP = + (SELECT e.HELP + FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f + WHERE e.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE + AND e.ad_element_id = c.ad_element_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id), + istranslated = + (SELECT e.istranslated + FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f + WHERE e.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE + AND e.ad_element_id = c.ad_element_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id), + updated = current_timestamp + WHERE EXISTS ( + SELECT 1 + FROM AD_FIELD f, AD_ELEMENT_TRL e, AD_COLUMN c + WHERE AD_FIELD_TRL.ad_field_id = f.ad_field_id + AND f.ad_column_id = c.ad_column_id + AND c.ad_element_id = e.ad_element_id + AND c.ad_process_id IS NULL + AND AD_FIELD_TRL.AD_LANGUAGE = e.AD_LANGUAGE + AND f.iscentrallymaintained = 'Y' + AND f.isactive = 'Y' + AND ( AD_FIELD_TRL.NAME <> e.NAME + OR COALESCE (AD_FIELD_TRL.description, ' ') <> COALESCE (e.description, ' ') + OR COALESCE (AD_FIELD_TRL.HELP, ' ') <> COALESCE (e.HELP, ' ') + )); + +UPDATE AD_FIELD + SET NAME = + (SELECT e.po_name + FROM AD_ELEMENT e, AD_COLUMN c + WHERE e.ad_element_id = c.ad_element_id + AND c.ad_column_id = AD_FIELD.ad_column_id), + description = + (SELECT e.po_description + FROM AD_ELEMENT e, AD_COLUMN c + WHERE e.ad_element_id = c.ad_element_id + AND c.ad_column_id = AD_FIELD.ad_column_id), + HELP = + (SELECT e.po_help + FROM AD_ELEMENT e, AD_COLUMN c + WHERE e.ad_element_id = c.ad_element_id + AND c.ad_column_id = AD_FIELD.ad_column_id), + updated = current_timestamp + WHERE AD_FIELD.iscentrallymaintained = 'Y' + AND AD_FIELD.isactive = 'Y' + AND EXISTS ( + SELECT 1 + FROM AD_ELEMENT e, AD_COLUMN c + WHERE AD_FIELD.ad_column_id = c.ad_column_id + AND c.ad_element_id = e.ad_element_id + AND c.ad_process_id IS NULL + AND ( AD_FIELD.NAME <> e.po_name + OR COALESCE (AD_FIELD.description, ' ') <> COALESCE (e.po_description, ' ') + OR COALESCE (AD_FIELD.HELP, ' ') <> COALESCE (e.po_help, ' ') + ) + AND e.po_name IS NOT NULL) + AND EXISTS ( + SELECT 1 + FROM AD_TAB t, AD_WINDOW w + WHERE AD_FIELD.ad_tab_id = t.ad_tab_id + AND t.ad_window_id = w.ad_window_id + AND w.issotrx = 'N'); + +UPDATE AD_FIELD_TRL + SET NAME = + (SELECT e.po_name + FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f + WHERE e.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE + AND e.ad_element_id = c.ad_element_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id), + description = + (SELECT e.po_description + FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f + WHERE e.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE + AND e.ad_element_id = c.ad_element_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id), + HELP = + (SELECT e.po_help + FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f + WHERE e.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE + AND e.ad_element_id = c.ad_element_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id), + istranslated = + (SELECT e.istranslated + FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f + WHERE e.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE + AND e.ad_element_id = c.ad_element_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id), + updated = current_timestamp + WHERE EXISTS ( + SELECT 1 + FROM AD_FIELD f, AD_ELEMENT_TRL e, AD_COLUMN c + WHERE AD_FIELD_TRL.ad_field_id = f.ad_field_id + AND f.ad_column_id = c.ad_column_id + AND c.ad_element_id = e.ad_element_id + AND c.ad_process_id IS NULL + AND AD_FIELD_TRL.AD_LANGUAGE = e.AD_LANGUAGE + AND f.iscentrallymaintained = 'Y' + AND f.isactive = 'Y' + AND ( AD_FIELD_TRL.NAME <> e.po_name + OR COALESCE (AD_FIELD_TRL.description, ' ') <> COALESCE (e.po_description, ' ') + OR COALESCE (AD_FIELD_TRL.HELP, ' ') <> COALESCE (e.po_help, ' ') + ) + AND e.po_name IS NOT NULL) + AND EXISTS ( + SELECT 1 + FROM AD_FIELD f, AD_TAB t, AD_WINDOW w + WHERE AD_FIELD_TRL.ad_field_id = f.ad_field_id + AND f.ad_tab_id = t.ad_tab_id + AND t.ad_window_id = w.ad_window_id + AND w.issotrx = 'N'); + +UPDATE AD_FIELD + SET NAME = + (SELECT p.NAME + FROM AD_PROCESS p, AD_COLUMN c + WHERE p.ad_process_id = c.ad_process_id + AND c.ad_column_id = AD_FIELD.ad_column_id), + description = + (SELECT p.description + FROM AD_PROCESS p, AD_COLUMN c + WHERE p.ad_process_id = c.ad_process_id + AND c.ad_column_id = AD_FIELD.ad_column_id), + HELP = + (SELECT p.HELP + FROM AD_PROCESS p, AD_COLUMN c + WHERE p.ad_process_id = c.ad_process_id + AND c.ad_column_id = AD_FIELD.ad_column_id), + updated = current_timestamp + WHERE AD_FIELD.iscentrallymaintained = 'Y' + AND AD_FIELD.isactive = 'Y' + AND EXISTS ( + SELECT 1 + FROM AD_PROCESS p, AD_COLUMN c + WHERE c.ad_process_id = p.ad_process_id + AND AD_FIELD.ad_column_id = c.ad_column_id + AND ( AD_FIELD.NAME <> p.NAME + OR COALESCE (AD_FIELD.description, ' ') <> COALESCE (p.description, ' ') + OR COALESCE (AD_FIELD.HELP, ' ') <> COALESCE (p.HELP, ' ') + )); + +UPDATE AD_FIELD_TRL + SET NAME = + (SELECT p.NAME + FROM AD_PROCESS_TRL p, AD_COLUMN c, AD_FIELD f + WHERE p.ad_process_id = c.ad_process_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id + AND p.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE), + description = + (SELECT p.description + FROM AD_PROCESS_TRL p, AD_COLUMN c, AD_FIELD f + WHERE p.ad_process_id = c.ad_process_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id + AND p.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE), + HELP = + (SELECT p.HELP + FROM AD_PROCESS_TRL p, AD_COLUMN c, AD_FIELD f + WHERE p.ad_process_id = c.ad_process_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id + AND p.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE), + istranslated = + (SELECT p.istranslated + FROM AD_PROCESS_TRL p, AD_COLUMN c, AD_FIELD f + WHERE p.ad_process_id = c.ad_process_id + AND c.ad_column_id = f.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id + AND p.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE), + updated = current_timestamp + WHERE EXISTS ( + SELECT 1 + FROM AD_PROCESS_TRL p, AD_COLUMN c, AD_FIELD f + WHERE c.ad_process_id = p.ad_process_id + AND f.ad_column_id = c.ad_column_id + AND f.ad_field_id = AD_FIELD_TRL.ad_field_id + AND p.AD_LANGUAGE = AD_FIELD_TRL.AD_LANGUAGE + AND f.iscentrallymaintained = 'Y' + AND f.isactive = 'Y' + AND ( AD_FIELD_TRL.NAME <> p.NAME + OR COALESCE (AD_FIELD_TRL.description, ' ') <> COALESCE (p.description, ' ') + OR COALESCE (AD_FIELD_TRL.HELP, ' ') <> COALESCE (p.HELP, ' ') + )); + +/* +-- check for element errors +SELECT UPPER (e.columnname), COUNT (*) + FROM AD_ELEMENT e +GROUP BY UPPER (e.columnname) + HAVING COUNT (*) > 1; + +SELECT ROWID, ad_element_id, columnname, + (SELECT COUNT (*) + FROM AD_COLUMN c + WHERE c.ad_element_id = AD_ELEMENT.ad_element_id) cnt + FROM AD_ELEMENT + WHERE UPPER (columnname) IN (SELECT UPPER (e.columnname) + FROM AD_ELEMENT e + GROUP BY UPPER (e.columnname) + HAVING COUNT (*) > 1) +ORDER BY UPPER (columnname), columnname; +*/ + +UPDATE AD_PROCESS_PARA + SET columnname = (SELECT e.columnname + FROM AD_ELEMENT e + -- WHERE UPPER (e.columnname) = UPPER (AD_PROCESS_PARA.columnname)) + WHERE e.columnname = AD_PROCESS_PARA.columnname) -- Temporary patch Fixed Assets are broking it + WHERE AD_PROCESS_PARA.iscentrallymaintained = 'Y' + AND AD_PROCESS_PARA.isactive = 'Y' + AND EXISTS ( + SELECT 1 + FROM AD_ELEMENT e + WHERE UPPER (e.columnname) = UPPER (AD_PROCESS_PARA.columnname) + AND e.columnname <> AD_PROCESS_PARA.columnname); + +UPDATE AD_PROCESS_PARA + SET iscentrallymaintained = 'N' + WHERE iscentrallymaintained <> 'N' + AND NOT EXISTS (SELECT 1 + FROM AD_ELEMENT e + WHERE AD_PROCESS_PARA.columnname = e.columnname); + +UPDATE AD_PROCESS_PARA + SET NAME = (SELECT e.NAME + FROM AD_ELEMENT e + WHERE e.columnname = AD_PROCESS_PARA.columnname), + description = (SELECT e.description + FROM AD_ELEMENT e + WHERE e.columnname = AD_PROCESS_PARA.columnname), + HELP = (SELECT e.HELP + FROM AD_ELEMENT e + WHERE e.columnname = AD_PROCESS_PARA.columnname), + updated = current_timestamp + WHERE AD_PROCESS_PARA.iscentrallymaintained = 'Y' + AND AD_PROCESS_PARA.isactive = 'Y' + AND EXISTS ( + SELECT 1 + FROM AD_ELEMENT e + WHERE e.columnname = AD_PROCESS_PARA.columnname + AND ( AD_PROCESS_PARA.NAME <> e.NAME + OR COALESCE (AD_PROCESS_PARA.description, ' ') <> COALESCE (e.description, ' ') + OR COALESCE (AD_PROCESS_PARA.HELP, ' ') <> COALESCE (e.HELP, ' ') + )); + +UPDATE AD_PROCESS_PARA_TRL + SET NAME = + (SELECT et.NAME + FROM AD_ELEMENT_TRL et, AD_ELEMENT e, AD_PROCESS_PARA f + WHERE et.AD_LANGUAGE = AD_PROCESS_PARA_TRL.AD_LANGUAGE + AND et.ad_element_id = e.ad_element_id + AND e.columnname = f.columnname + AND f.ad_process_para_id = AD_PROCESS_PARA_TRL.ad_process_para_id), + description = + (SELECT et.description + FROM AD_ELEMENT_TRL et, AD_ELEMENT e, AD_PROCESS_PARA f + WHERE et.AD_LANGUAGE = AD_PROCESS_PARA_TRL.AD_LANGUAGE + AND et.ad_element_id = e.ad_element_id + AND e.columnname = f.columnname + AND f.ad_process_para_id = AD_PROCESS_PARA_TRL.ad_process_para_id), + HELP = + (SELECT et.HELP + FROM AD_ELEMENT_TRL et, AD_ELEMENT e, AD_PROCESS_PARA f + WHERE et.AD_LANGUAGE = AD_PROCESS_PARA_TRL.AD_LANGUAGE + AND et.ad_element_id = e.ad_element_id + AND e.columnname = f.columnname + AND f.ad_process_para_id = AD_PROCESS_PARA_TRL.ad_process_para_id), + istranslated = + (SELECT et.istranslated + FROM AD_ELEMENT_TRL et, AD_ELEMENT e, AD_PROCESS_PARA f + WHERE et.AD_LANGUAGE = AD_PROCESS_PARA_TRL.AD_LANGUAGE + AND et.ad_element_id = e.ad_element_id + AND e.columnname = f.columnname + AND f.ad_process_para_id = AD_PROCESS_PARA_TRL.ad_process_para_id), + updated = current_timestamp + WHERE EXISTS ( + SELECT 1 + FROM AD_ELEMENT_TRL et, AD_ELEMENT e, AD_PROCESS_PARA f + WHERE et.AD_LANGUAGE = AD_PROCESS_PARA_TRL.AD_LANGUAGE + AND et.ad_element_id = e.ad_element_id + AND e.columnname = f.columnname + AND f.ad_process_para_id = AD_PROCESS_PARA_TRL.ad_process_para_id + AND f.iscentrallymaintained = 'Y' + AND f.isactive = 'Y' + AND ( AD_PROCESS_PARA_TRL.NAME <> et.NAME + OR COALESCE (AD_PROCESS_PARA_TRL.description, ' ') <> COALESCE (et.description, ' ') + OR COALESCE (AD_PROCESS_PARA_TRL.HELP, ' ') <> COALESCE (et.HELP, ' ') + )); + +UPDATE AD_WF_NODE + SET NAME = (SELECT w.NAME + FROM AD_WINDOW w + WHERE w.ad_window_id = AD_WF_NODE.ad_window_id), + description = (SELECT w.description + FROM AD_WINDOW w + WHERE w.ad_window_id = AD_WF_NODE.ad_window_id), + HELP = (SELECT w.HELP + FROM AD_WINDOW w + WHERE w.ad_window_id = AD_WF_NODE.ad_window_id) + WHERE AD_WF_NODE.iscentrallymaintained = 'Y' + AND EXISTS ( + SELECT 1 + FROM AD_WINDOW w + WHERE w.ad_window_id = AD_WF_NODE.ad_window_id + AND ( w.NAME <> AD_WF_NODE.NAME + OR COALESCE (w.description, ' ') <> COALESCE (AD_WF_NODE.description, ' ') + OR COALESCE (w.HELP, ' ') <> COALESCE (AD_WF_NODE.HELP, ' ') + )); + +UPDATE AD_WF_NODE_TRL + SET NAME = + (SELECT t.NAME + FROM AD_WINDOW_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_window_id = t.ad_window_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE), + description = + (SELECT t.description + FROM AD_WINDOW_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_window_id = t.ad_window_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE), + HELP = + (SELECT t.HELP + FROM AD_WINDOW_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_window_id = t.ad_window_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE) + WHERE EXISTS ( + SELECT 1 + FROM AD_WINDOW_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_window_id = t.ad_window_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE + AND n.iscentrallymaintained = 'Y' + AND n.isactive = 'Y' + AND ( AD_WF_NODE_TRL.NAME <> t.NAME + OR COALESCE (AD_WF_NODE_TRL.description, ' ') <> COALESCE (t.description, ' ') + OR COALESCE (AD_WF_NODE_TRL.HELP, ' ') <> COALESCE (t.HELP, ' ') + )); + +UPDATE AD_WF_NODE + SET NAME = + (SELECT f.NAME + FROM AD_FORM f + WHERE f.ad_form_id = AD_WF_NODE.ad_form_id), + description = + (SELECT f.description + FROM AD_FORM f + WHERE f.ad_form_id = AD_WF_NODE.ad_form_id), + HELP = + (SELECT f.HELP + FROM AD_FORM f + WHERE f.ad_form_id = AD_WF_NODE.ad_form_id) + WHERE AD_WF_NODE.iscentrallymaintained = 'Y' + AND EXISTS ( + SELECT 1 + FROM AD_FORM f + WHERE f.ad_form_id = AD_WF_NODE.ad_form_id + AND ( f.NAME <> AD_WF_NODE.NAME + OR COALESCE (f.description, ' ') <> COALESCE (AD_WF_NODE.description, ' ') + OR COALESCE (f.HELP, ' ') <> COALESCE (AD_WF_NODE.HELP, ' ') + )); + +UPDATE AD_WF_NODE_TRL + SET NAME = + (SELECT t.NAME + FROM AD_FORM_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_form_id = t.ad_form_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE), + description = + (SELECT t.description + FROM AD_FORM_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_form_id = t.ad_form_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE), + HELP = + (SELECT t.HELP + FROM AD_FORM_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_form_id = t.ad_form_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE) + WHERE EXISTS ( + SELECT 1 + FROM AD_FORM_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_form_id = t.ad_form_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE + AND n.iscentrallymaintained = 'Y' + AND n.isactive = 'Y' + AND ( AD_WF_NODE_TRL.NAME <> t.NAME + OR COALESCE (AD_WF_NODE_TRL.description, ' ') <> COALESCE (t.description, ' ') + OR COALESCE (AD_WF_NODE_TRL.HELP, ' ') <> COALESCE (t.HELP, ' ') + )); + +UPDATE AD_WF_NODE + SET NAME = + (SELECT f.NAME + FROM AD_PROCESS f + WHERE f.ad_process_id = AD_WF_NODE.ad_process_id), + description = + (SELECT f.description + FROM AD_PROCESS f + WHERE f.ad_process_id = AD_WF_NODE.ad_process_id), + HELP = + (SELECT f.HELP + FROM AD_PROCESS f + WHERE f.ad_process_id = AD_WF_NODE.ad_process_id) + WHERE AD_WF_NODE.iscentrallymaintained = 'Y' + AND EXISTS ( + SELECT 1 + FROM AD_PROCESS f + WHERE f.ad_process_id = AD_WF_NODE.ad_process_id + AND ( f.NAME <> AD_WF_NODE.NAME + OR COALESCE (f.description, ' ') <> COALESCE (AD_WF_NODE.description, ' ') + OR COALESCE (f.HELP, ' ') <> COALESCE (AD_WF_NODE.HELP, ' ') + )); + +UPDATE AD_WF_NODE_TRL + SET NAME = + (SELECT t.NAME + FROM AD_PROCESS_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_process_id = t.ad_process_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE), + description = + (SELECT t.description + FROM AD_PROCESS_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_process_id = t.ad_process_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE), + HELP = + (SELECT t.HELP + FROM AD_PROCESS_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_process_id = t.ad_process_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE) + WHERE EXISTS ( + SELECT 1 + FROM AD_PROCESS_TRL t, AD_WF_NODE n + WHERE AD_WF_NODE_TRL.ad_wf_node_id = n.ad_wf_node_id + AND n.ad_process_id = t.ad_process_id + AND AD_WF_NODE_TRL.AD_LANGUAGE = t.AD_LANGUAGE + AND n.iscentrallymaintained = 'Y' + AND n.isactive = 'Y' + AND ( AD_WF_NODE_TRL.NAME <> t.NAME + OR COALESCE (AD_WF_NODE_TRL.description, ' ') <> COALESCE (t.description, ' ') + OR COALESCE (AD_WF_NODE_TRL.HELP, ' ') <> COALESCE (t.HELP, ' ') + )); + +UPDATE AD_PRINTFORMATITEM + SET NAME = + (SELECT e.NAME + FROM AD_ELEMENT e, AD_COLUMN c + WHERE e.ad_element_id = c.ad_element_id + AND c.ad_column_id = AD_PRINTFORMATITEM.ad_column_id) + WHERE AD_PRINTFORMATITEM.iscentrallymaintained = 'Y' + AND EXISTS ( + SELECT 1 + FROM AD_ELEMENT e, AD_COLUMN c + WHERE e.ad_element_id = c.ad_element_id + AND c.ad_column_id = AD_PRINTFORMATITEM.ad_column_id + AND e.NAME <> AD_PRINTFORMATITEM.NAME) + AND EXISTS ( + SELECT 1 + FROM AD_CLIENT + WHERE ad_client_id = AD_PRINTFORMATITEM.ad_client_id + AND ismultilingualdocument = 'Y'); + +UPDATE AD_PRINTFORMATITEM + SET printname = + (SELECT e.printname + FROM AD_ELEMENT e, AD_COLUMN c + WHERE e.ad_element_id = c.ad_element_id + AND c.ad_column_id = AD_PRINTFORMATITEM.ad_column_id) + WHERE AD_PRINTFORMATITEM.iscentrallymaintained = 'Y' + AND EXISTS ( + SELECT 1 + FROM AD_ELEMENT e, AD_COLUMN c, AD_PRINTFORMAT pf + WHERE e.ad_element_id = c.ad_element_id + AND c.ad_column_id = AD_PRINTFORMATITEM.ad_column_id + AND LENGTH (AD_PRINTFORMATITEM.printname) > 0 + AND e.printname <> AD_PRINTFORMATITEM.printname + AND pf.ad_printformat_id = AD_PRINTFORMATITEM.ad_printformat_id + AND pf.isform = 'N' + AND istablebased = 'Y') + AND EXISTS ( + SELECT 1 + FROM AD_CLIENT + WHERE ad_client_id = AD_PRINTFORMATITEM.ad_client_id + AND ismultilingualdocument = 'Y'); + +UPDATE AD_PRINTFORMATITEM_TRL + SET printname = + (SELECT e.printname + FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_PRINTFORMATITEM pfi + WHERE e.AD_LANGUAGE = AD_PRINTFORMATITEM_TRL.AD_LANGUAGE + AND e.ad_element_id = c.ad_element_id + AND c.ad_column_id = pfi.ad_column_id + AND pfi.ad_printformatitem_id = AD_PRINTFORMATITEM_TRL.ad_printformatitem_id) + WHERE EXISTS ( + SELECT 1 + FROM AD_ELEMENT_TRL e, + AD_COLUMN c, + AD_PRINTFORMATITEM pfi, + AD_PRINTFORMAT pf + WHERE e.AD_LANGUAGE = AD_PRINTFORMATITEM_TRL.AD_LANGUAGE + AND e.ad_element_id = c.ad_element_id + AND c.ad_column_id = pfi.ad_column_id + AND pfi.ad_printformatitem_id = AD_PRINTFORMATITEM_TRL.ad_printformatitem_id + AND pfi.iscentrallymaintained = 'Y' + AND LENGTH (pfi.printname) > 0 + AND (e.printname <> AD_PRINTFORMATITEM_TRL.printname OR AD_PRINTFORMATITEM_TRL.printname IS NULL) + AND pf.ad_printformat_id = pfi.ad_printformat_id + AND pf.isform = 'N' + AND istablebased = 'Y') + AND EXISTS ( + SELECT 1 + FROM AD_CLIENT + WHERE ad_client_id = AD_PRINTFORMATITEM_TRL.ad_client_id + AND ismultilingualdocument = 'Y'); + +UPDATE AD_PRINTFORMATITEM_TRL + SET printname = + (SELECT pfi.printname + FROM AD_PRINTFORMATITEM pfi + WHERE pfi.ad_printformatitem_id = AD_PRINTFORMATITEM_TRL.ad_printformatitem_id) + WHERE EXISTS ( + SELECT 1 + FROM AD_PRINTFORMATITEM pfi, AD_PRINTFORMAT pf + WHERE pfi.ad_printformatitem_id = AD_PRINTFORMATITEM_TRL.ad_printformatitem_id + AND pfi.iscentrallymaintained = 'Y' + AND LENGTH (pfi.printname) > 0 + AND pfi.printname <> AD_PRINTFORMATITEM_TRL.printname + AND pf.ad_printformat_id = pfi.ad_printformat_id + AND pf.isform = 'N' + AND pf.istablebased = 'Y') + AND EXISTS ( + SELECT 1 + FROM AD_CLIENT + WHERE ad_client_id = AD_PRINTFORMATITEM_TRL.ad_client_id + AND ismultilingualdocument = 'N'); + +UPDATE AD_PRINTFORMATITEM_TRL + SET printname = NULL + WHERE printname IS NOT NULL + AND EXISTS ( + SELECT 1 + FROM AD_PRINTFORMATITEM pfi + WHERE pfi.ad_printformatitem_id = AD_PRINTFORMATITEM_TRL.ad_printformatitem_id + AND pfi.iscentrallymaintained = 'Y' + AND (LENGTH (pfi.printname) = 0 OR pfi.printname IS NULL)); + +UPDATE AD_MENU + SET NAME = (SELECT NAME + FROM AD_WINDOW w + WHERE AD_MENU.ad_window_id = w.ad_window_id), + description = (SELECT description + FROM AD_WINDOW w + WHERE AD_MENU.ad_window_id = w.ad_window_id) + WHERE ad_window_id IS NOT NULL AND action = 'W'; + +UPDATE AD_MENU_TRL + SET NAME = + (SELECT wt.NAME + FROM AD_WINDOW_TRL wt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_window_id = wt.ad_window_id + AND AD_MENU_TRL.AD_LANGUAGE = wt.AD_LANGUAGE), + description = + (SELECT wt.description + FROM AD_WINDOW_TRL wt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_window_id = wt.ad_window_id + AND AD_MENU_TRL.AD_LANGUAGE = wt.AD_LANGUAGE), + istranslated = + (SELECT wt.istranslated + FROM AD_WINDOW_TRL wt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_window_id = wt.ad_window_id + AND AD_MENU_TRL.AD_LANGUAGE = wt.AD_LANGUAGE) + WHERE EXISTS ( + SELECT 1 + FROM AD_WINDOW_TRL wt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_window_id = wt.ad_window_id + AND AD_MENU_TRL.AD_LANGUAGE = wt.AD_LANGUAGE + AND m.ad_window_id IS NOT NULL + AND m.action = 'W'); + +UPDATE AD_MENU + SET NAME = (SELECT p.NAME + FROM AD_PROCESS p + WHERE AD_MENU.ad_process_id = p.ad_process_id), + description = (SELECT p.description + FROM AD_PROCESS p + WHERE AD_MENU.ad_process_id = p.ad_process_id) + WHERE AD_MENU.ad_process_id IS NOT NULL AND AD_MENU.action IN ('R', 'P'); + +UPDATE AD_MENU_TRL + SET NAME = + (SELECT pt.NAME + FROM AD_PROCESS_TRL pt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_process_id = pt.ad_process_id + AND AD_MENU_TRL.AD_LANGUAGE = pt.AD_LANGUAGE), + description = + (SELECT pt.description + FROM AD_PROCESS_TRL pt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_process_id = pt.ad_process_id + AND AD_MENU_TRL.AD_LANGUAGE = pt.AD_LANGUAGE), + istranslated = + (SELECT pt.istranslated + FROM AD_PROCESS_TRL pt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_process_id = pt.ad_process_id + AND AD_MENU_TRL.AD_LANGUAGE = pt.AD_LANGUAGE) + WHERE EXISTS ( + SELECT 1 + FROM AD_PROCESS_TRL pt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_process_id = pt.ad_process_id + AND AD_MENU_TRL.AD_LANGUAGE = pt.AD_LANGUAGE + AND m.ad_process_id IS NOT NULL + AND action IN ('R', 'P')); + +UPDATE AD_MENU + SET NAME = (SELECT NAME + FROM AD_FORM f + WHERE AD_MENU.ad_form_id = f.ad_form_id), + description = (SELECT description + FROM AD_FORM f + WHERE AD_MENU.ad_form_id = f.ad_form_id) + WHERE ad_form_id IS NOT NULL AND action = 'X'; + +UPDATE AD_MENU_TRL + SET NAME = + (SELECT ft.NAME + FROM AD_FORM_TRL ft, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_form_id = ft.ad_form_id + AND AD_MENU_TRL.AD_LANGUAGE = ft.AD_LANGUAGE), + description = + (SELECT ft.description + FROM AD_FORM_TRL ft, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_form_id = ft.ad_form_id + AND AD_MENU_TRL.AD_LANGUAGE = ft.AD_LANGUAGE), + istranslated = + (SELECT ft.istranslated + FROM AD_FORM_TRL ft, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_form_id = ft.ad_form_id + AND AD_MENU_TRL.AD_LANGUAGE = ft.AD_LANGUAGE) + WHERE EXISTS ( + SELECT 1 + FROM AD_FORM_TRL ft, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_form_id = ft.ad_form_id + AND AD_MENU_TRL.AD_LANGUAGE = ft.AD_LANGUAGE + AND m.ad_form_id IS NOT NULL + AND action = 'X'); + +UPDATE AD_MENU + SET NAME = (SELECT p.NAME + FROM AD_WORKFLOW p + WHERE AD_MENU.ad_workflow_id = p.ad_workflow_id), + description = (SELECT p.description + FROM AD_WORKFLOW p + WHERE AD_MENU.ad_workflow_id = p.ad_workflow_id) + WHERE AD_MENU.ad_workflow_id IS NOT NULL AND AD_MENU.action = 'F'; + +UPDATE AD_MENU_TRL + SET NAME = + (SELECT pt.NAME + FROM AD_WORKFLOW_TRL pt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_workflow_id = pt.ad_workflow_id + AND AD_MENU_TRL.AD_LANGUAGE = pt.AD_LANGUAGE), + description = + (SELECT pt.description + FROM AD_WORKFLOW_TRL pt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_workflow_id = pt.ad_workflow_id + AND AD_MENU_TRL.AD_LANGUAGE = pt.AD_LANGUAGE), + istranslated = + (SELECT pt.istranslated + FROM AD_WORKFLOW_TRL pt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_workflow_id = pt.ad_workflow_id + AND AD_MENU_TRL.AD_LANGUAGE = pt.AD_LANGUAGE) + WHERE EXISTS ( + SELECT 1 + FROM AD_WORKFLOW_TRL pt, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_workflow_id = pt.ad_workflow_id + AND AD_MENU_TRL.AD_LANGUAGE = pt.AD_LANGUAGE + AND m.ad_workflow_id IS NOT NULL + AND action = 'F'); + +UPDATE AD_MENU + SET NAME = (SELECT NAME + FROM AD_TASK f + WHERE AD_MENU.ad_task_id = f.ad_task_id), + description = (SELECT description + FROM AD_TASK f + WHERE AD_MENU.ad_task_id = f.ad_task_id) + WHERE ad_task_id IS NOT NULL AND action = 'T'; + +UPDATE AD_MENU_TRL + SET NAME = + (SELECT ft.NAME + FROM AD_TASK_TRL ft, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_task_id = ft.ad_task_id + AND AD_MENU_TRL.AD_LANGUAGE = ft.AD_LANGUAGE), + description = + (SELECT ft.description + FROM AD_TASK_TRL ft, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_task_id = ft.ad_task_id + AND AD_MENU_TRL.AD_LANGUAGE = ft.AD_LANGUAGE), + istranslated = + (SELECT ft.istranslated + FROM AD_TASK_TRL ft, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_task_id = ft.ad_task_id + AND AD_MENU_TRL.AD_LANGUAGE = ft.AD_LANGUAGE) + WHERE EXISTS ( + SELECT 1 + FROM AD_TASK_TRL ft, AD_MENU m + WHERE AD_MENU_TRL.ad_menu_id = m.ad_menu_id + AND m.ad_task_id = ft.ad_task_id + AND AD_MENU_TRL.AD_LANGUAGE = ft.AD_LANGUAGE + AND m.ad_task_id IS NOT NULL + AND action = 'T'); + +UPDATE AD_COLUMN + SET NAME = + (SELECT e.NAME + FROM AD_ELEMENT e + WHERE AD_COLUMN.ad_element_id = e.ad_element_id), + description = + (SELECT e.description + FROM AD_ELEMENT e + WHERE AD_COLUMN.ad_element_id = e.ad_element_id), + HELP = + (SELECT e.HELP + FROM AD_ELEMENT e + WHERE AD_COLUMN.ad_element_id = e.ad_element_id) + WHERE EXISTS (SELECT 1 + FROM AD_ELEMENT e + WHERE AD_COLUMN.ad_element_id = e.ad_element_id AND AD_COLUMN.NAME <> e.NAME); + +UPDATE AD_COLUMN_TRL + SET NAME = + (SELECT e.NAME + FROM AD_COLUMN c INNER JOIN AD_ELEMENT_TRL e + ON (c.ad_element_id = e.ad_element_id) + WHERE AD_COLUMN_TRL.ad_column_id = c.ad_column_id + AND AD_COLUMN_TRL.AD_LANGUAGE = e.AD_LANGUAGE) + WHERE EXISTS ( + SELECT 1 + FROM AD_COLUMN c INNER JOIN AD_ELEMENT_TRL e + ON (c.ad_element_id = e.ad_element_id) + WHERE AD_COLUMN_TRL.ad_column_id = c.ad_column_id + AND AD_COLUMN_TRL.AD_LANGUAGE = e.AD_LANGUAGE + AND AD_COLUMN_TRL.NAME <> e.NAME); + +UPDATE AD_TABLE + SET NAME = + (SELECT e.NAME + FROM AD_ELEMENT e + WHERE AD_TABLE.tablename || '_ID' = e.columnname), + description = + (SELECT e.description + FROM AD_ELEMENT e + WHERE AD_TABLE.tablename || '_ID' = e.columnname) + WHERE EXISTS (SELECT 1 + FROM AD_ELEMENT e + WHERE AD_TABLE.tablename || '_ID' = e.columnname AND AD_TABLE.NAME <> e.NAME); + +UPDATE AD_TABLE_TRL + SET NAME = + (SELECT e.NAME + FROM AD_TABLE t INNER JOIN AD_ELEMENT ex + ON (t.tablename || '_ID' = ex.columnname) + INNER JOIN AD_ELEMENT_TRL e + ON (ex.ad_element_id = e.ad_element_id) + WHERE AD_TABLE_TRL.ad_table_id = t.ad_table_id + AND AD_TABLE_TRL.AD_LANGUAGE = e.AD_LANGUAGE) + WHERE EXISTS ( + SELECT 1 + FROM AD_TABLE t INNER JOIN AD_ELEMENT ex + ON (t.tablename || '_ID' = ex.columnname) + INNER JOIN AD_ELEMENT_TRL e + ON (ex.ad_element_id = e.ad_element_id) + WHERE AD_TABLE_TRL.ad_table_id = t.ad_table_id + AND AD_TABLE_TRL.AD_LANGUAGE = e.AD_LANGUAGE + AND AD_TABLE_TRL.NAME <> e.NAME); + +UPDATE AD_TABLE + SET NAME = + (SELECT e.NAME || ' Trl' + FROM AD_ELEMENT e + WHERE SUBSTR (AD_TABLE.tablename, 1, LENGTH (AD_TABLE.tablename) - 4) || '_ID' = + e.columnname), + description = + (SELECT e.description + FROM AD_ELEMENT e + WHERE SUBSTR (AD_TABLE.tablename, 1, LENGTH (AD_TABLE.tablename) - 4) || '_ID' = + e.columnname) + WHERE tablename LIKE '%_Trl' + AND EXISTS ( + SELECT 1 + FROM AD_ELEMENT e + WHERE SUBSTR (AD_TABLE.tablename, 1, LENGTH (AD_TABLE.tablename) - 4) || '_ID' = + e.columnname + AND AD_TABLE.NAME <> e.NAME); + +UPDATE AD_TABLE_TRL + SET NAME = + (SELECT e.NAME || ' **' + FROM AD_TABLE t INNER JOIN AD_ELEMENT ex + ON (SUBSTR (t.tablename, 1, LENGTH (t.tablename) - 4) + || '_ID' = ex.columnname + ) + INNER JOIN AD_ELEMENT_TRL e + ON (ex.ad_element_id = e.ad_element_id) + WHERE AD_TABLE_TRL.ad_table_id = t.ad_table_id + AND AD_TABLE_TRL.AD_LANGUAGE = e.AD_LANGUAGE) + WHERE EXISTS ( + SELECT 1 + FROM AD_TABLE t INNER JOIN AD_ELEMENT ex + ON (SUBSTR (t.tablename, 1, LENGTH (t.tablename) - 4) + || '_ID' = ex.columnname + ) + INNER JOIN AD_ELEMENT_TRL e + ON (ex.ad_element_id = e.ad_element_id) + WHERE AD_TABLE_TRL.ad_table_id = t.ad_table_id + AND AD_TABLE_TRL.AD_LANGUAGE = e.AD_LANGUAGE + AND t.tablename LIKE '%_Trl' + AND AD_TABLE_TRL.NAME <> e.NAME); + +COMMIT ; +CREATE OR REPLACE FUNCTION update_sequences() RETURNS void as $func$ +-- TODO: Currently not inserting new sequences +DECLARE + cmdsys VARCHAR (1000); + cmdnosys VARCHAR (1000); + cmdseq VARCHAR (1000); + cmdupd VARCHAR (1000); + currentnextsys NUMERIC (10); + currentnext NUMERIC (10); + currentseqsys NUMERIC (10); + currentseq NUMERIC (10); + ok BOOLEAN; + r RECORD; +BEGIN + + FOR r IN (SELECT tablename + FROM AD_TABLE t + WHERE EXISTS ( + SELECT 1 + FROM AD_COLUMN c + WHERE t.ad_table_id = c.ad_table_id + AND c.columnname = t.tablename || '_ID') + ORDER BY 1) + LOOP + cmdsys := + 'SELECT MAX (' + || r.tablename + || '_id) as currentnextsys FROM ' + || r.tablename + || ' where ' + || r.tablename + || '_id<1000000'; + + ok := true; + BEGIN + EXECUTE cmdsys INTO currentnextsys; + EXCEPTION + WHEN OTHERS + THEN + ok := false; + END; + + IF ok THEN + IF currentnextsys IS NULL + THEN + currentnextsys := 0; + END IF; + + SELECT INTO currentnextsys CASE SIGN (currentnextsys - 50000) + WHEN -1 THEN 50000 + ELSE coalesce (currentnextsys + 1, 50000) + END; + + cmdnosys := + 'SELECT MAX (' + || r.tablename + || '_id) as currentnext FROM ' + || r.tablename + || ' where ' + || r.tablename + || '_id>=1000000'; + + EXECUTE cmdnosys INTO currentnext; + + IF currentnext IS NULL + THEN + currentnext := 0; + END IF; + + SELECT INTO currentnext CASE SIGN (currentnext - 1000000) + WHEN -1 THEN 1000000 + ELSE coalesce (currentnext + 1, 1000000) + END ; + + cmdseq := + 'SELECT currentnext, currentnextsys FROM AD_Sequence ' + || 'WHERE Name = ''' + || r.tablename + || ''' AND istableid = ''Y'''; + + EXECUTE cmdseq INTO currentseq, currentseqsys; + + IF currentnextsys <> currentseqsys OR currentnext <> currentseq + THEN + cmdupd := + 'update ad_sequence set currentnextsys = ' + || currentnextsys + || ', currentnext=' + || currentnext + || ' where name=''' + || r.tablename + || ''' and istableid=''Y'''; + + EXECUTE cmdupd; + END IF; + END IF; + + END LOOP; +END; +$func$ LANGUAGE plpgsql; + +select update_sequences(); + +commit; +CREATE OR REPLACE FUNCTION role_access_update() RETURNS void as $func$ +DECLARE + roleaccesslevel VARCHAR (200); + roleaccesslevelwin VARCHAR (200); + sqlins VARCHAR (2000); + r RECORD; +BEGIN + FOR r IN (SELECT ad_role_id, userlevel, NAME + FROM AD_ROLE + WHERE ismanual = 'N' + ORDER BY ad_role_id) + LOOP + DELETE FROM AD_WINDOW_ACCESS + WHERE ad_role_id = r.ad_role_id; + + DELETE FROM AD_PROCESS_ACCESS + WHERE ad_role_id = r.ad_role_id; + + DELETE FROM AD_FORM_ACCESS + WHERE ad_role_id = r.ad_role_id; + + DELETE FROM AD_WORKFLOW_ACCESS + WHERE ad_role_id = r.ad_role_id; + + IF r.userlevel = 'S ' -- system + THEN + roleaccesslevel := '(''4'',''7'',''6'')'; + roleaccesslevelwin := roleaccesslevel; + ELSIF r.userlevel = ' C ' -- client + THEN + roleaccesslevel := '(''7'',''6'',''3'',''2'')'; + roleaccesslevelwin := roleaccesslevel; + ELSIF r.userlevel = ' CO' -- client + org + THEN + roleaccesslevel := '(''7'',''6'',''3'',''2'',''1'')'; + roleaccesslevelwin := roleaccesslevel; + ELSE -- org or others + roleaccesslevel := '(''3'',''1'',''7'')'; + roleaccesslevelwin := + roleaccesslevel || ' AND w.Name NOT LIKE ''%(all)%'''; + END IF; + + sqlins := + 'INSERT INTO AD_Window_Access (AD_Window_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT w.AD_Window_ID, ' + || r.ad_role_id + || ',0,0,''Y'', Current_Timestamp,0, Current_Timestamp,0,''Y'' FROM AD_Window w INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID) INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) WHERE t.SeqNo=(SELECT MIN(SeqNo) FROM AD_Tab xt WHERE xt.AD_Window_ID=w.AD_Window_ID)AND tt.AccessLevel IN ' + || roleaccesslevelwin; + + EXECUTE sqlins; + + sqlins := + 'INSERT INTO AD_Process_Access (AD_Process_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT p.AD_Process_ID, ' + || r.ad_role_id + || ',0,0,''Y'', Current_Timestamp,0, Current_Timestamp,0,''Y'' FROM AD_Process p WHERE AccessLevel IN ' + || roleaccesslevel; + + EXECUTE sqlins; + + sqlins := + 'INSERT INTO AD_Form_Access (AD_Form_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT f.AD_Form_ID, ' + || r.ad_role_id + || ',0,0,''Y'', Current_Timestamp,0, Current_Timestamp,0,''Y'' FROM AD_Form f WHERE AccessLevel IN ' + || roleaccesslevel; + + EXECUTE sqlins; + + sqlins := + 'INSERT INTO AD_WorkFlow_Access (AD_WorkFlow_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT w.AD_WorkFlow_ID, ' + || r.ad_role_id + || ',0,0,''Y'', Current_Timestamp,0, Current_Timestamp,0,''Y'' FROM AD_WorkFlow w WHERE AccessLevel IN ' + || roleaccesslevel; + + EXECUTE sqlins; + END LOOP; + +END; +$func$ LANGUAGE plpgsql; + +select role_access_update(); + +commit;