From 3ca8cdd94a6c5eeb4b43d88eba10e2cc9fefbfb3 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Tue, 18 Dec 2007 16:06:53 +0000 Subject: [PATCH] [ 1846595 ] 2pack do not set the start node in a workflow after import - Added proper defer endElement processing handling. --- base/src/org/adempiere/pipo/Element.java | 2 + .../src/org/adempiere/pipo/PackInHandler.java | 37 ++++++++++--------- .../handler/SQLStatementElementHandler.java | 9 ++--- .../pipo/handler/WorkflowElementHandler.java | 2 +- .../handler/WorkflowNodeElementHandler.java | 1 + ...rkflowNodeNextConditionElementHandler.java | 1 + 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/base/src/org/adempiere/pipo/Element.java b/base/src/org/adempiere/pipo/Element.java index 1360087a16..afc4262094 100644 --- a/base/src/org/adempiere/pipo/Element.java +++ b/base/src/org/adempiere/pipo/Element.java @@ -43,6 +43,8 @@ public class Element { //skip this node public boolean skip = false; + public boolean deferEnd = false; + /** * @param uri * @param localName diff --git a/base/src/org/adempiere/pipo/PackInHandler.java b/base/src/org/adempiere/pipo/PackInHandler.java index a450eef588..6a6fa23cb8 100644 --- a/base/src/org/adempiere/pipo/PackInHandler.java +++ b/base/src/org/adempiere/pipo/PackInHandler.java @@ -647,7 +647,7 @@ public class PackInHandler extends DefaultHandler { ElementHandler handler = handlers.get(elementValue); if (handler != null) handler.endElement(m_ctx, e); - if (e.defer) + if (e.defer || e.deferEnd) defer.add(new DeferEntry(e, false)); else if (!e.skip) { if (log.isLoggable(Level.INFO)) @@ -673,24 +673,21 @@ public class PackInHandler extends DefaultHandler { do { int startSize = defer.size(); List tmp = new ArrayList(defer); - List startElements = new ArrayList(); defer.clear(); for (DeferEntry d : tmp) { if (d.startElement) { d.element.defer = false; d.element.unresolved = ""; d.element.pass++; - startElements.add(d.element); - } else { - if (d.element.defer && startElements.contains(d.element)) { - defer.add(d); - continue; - } else { - //only defer endElement - d.element.defer = false; + } else { + if (d.element.deferEnd) { + d.element.deferEnd = false; d.element.unresolved = ""; - d.element.pass++; - } + } + } + 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) { @@ -702,9 +699,13 @@ public class PackInHandler extends DefaultHandler { if (d.element.defer) defer.add(d); else if (!d.startElement) { - if (log.isLoggable(Level.INFO)) - log.info("Processed: " + d.element.getElementValue() + " - " - + d.element.attributes.getValue(0)); + 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(); @@ -714,10 +715,10 @@ public class PackInHandler extends DefaultHandler { if (defer.size() > 0) { int count = 0; for (DeferEntry d : defer) { - if (d.startElement) { + if (!d.startElement) { count++; - if (log.isLoggable(Level.INFO)) - log.info("Unresolved: " + d.element.getElementValue() + " - " + d.element.attributes.getValue(0) + ", " + d.element.unresolved); + 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."); diff --git a/base/src/org/adempiere/pipo/handler/SQLStatementElementHandler.java b/base/src/org/adempiere/pipo/handler/SQLStatementElementHandler.java index 0ad1965bae..a2f5bb3767 100644 --- a/base/src/org/adempiere/pipo/handler/SQLStatementElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/SQLStatementElementHandler.java @@ -70,16 +70,13 @@ public class SQLStatementElementHandler extends AbstractElementHandler { // Postgres needs to commit DDL statements if (m_con != null && !m_con.getAutoCommit()) m_con.commit(); + stmt.close(); } finally { m_con.close(); } } - /* else if(DB.isSybase() == true && DBType.equals("Sybase")){ - pstmt.executeUpdate(); - log.info("Exceuted SQL Statement for Sybase"); - } - */ } - catch (Exception e) { + pstmt.close(); + } catch (Exception e) { log.log(Level.SEVERE,"SQLSatement", e); } } diff --git a/base/src/org/adempiere/pipo/handler/WorkflowElementHandler.java b/base/src/org/adempiere/pipo/handler/WorkflowElementHandler.java index 5a0f15a773..eb603a996a 100644 --- a/base/src/org/adempiere/pipo/handler/WorkflowElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/WorkflowElementHandler.java @@ -178,7 +178,7 @@ public class WorkflowElementHandler extends AbstractElementHandler { MWorkflow m_Workflow = new MWorkflow(ctx, element.recordId, getTrxName(ctx)); int id = get_IDWithColumn(ctx, "AD_WF_Node", "Name", name); if (id <= 0) { - element.defer = true; + element.deferEnd = true; element.unresolved = "AD_WF_Node=" + name; return; } diff --git a/base/src/org/adempiere/pipo/handler/WorkflowNodeElementHandler.java b/base/src/org/adempiere/pipo/handler/WorkflowNodeElementHandler.java index 2db3fdb4f0..385762ec05 100644 --- a/base/src/org/adempiere/pipo/handler/WorkflowNodeElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/WorkflowNodeElementHandler.java @@ -50,6 +50,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler { } if (element.parent != null && element.parent.getElementValue().equals("workflow") && element.parent.defer) { + element.unresolved = "Parent element mark as defer: " + atts.getValue("ADWorkflowNameID"); element.defer = true; return; } diff --git a/base/src/org/adempiere/pipo/handler/WorkflowNodeNextConditionElementHandler.java b/base/src/org/adempiere/pipo/handler/WorkflowNodeNextConditionElementHandler.java index 15153a9476..35e9ed4c9f 100644 --- a/base/src/org/adempiere/pipo/handler/WorkflowNodeNextConditionElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/WorkflowNodeNextConditionElementHandler.java @@ -52,6 +52,7 @@ public class WorkflowNodeNextConditionElementHandler extends workflowName); if (workflowId <= 0) { element.defer = true; + element.unresolved = "AD_Workflow: " + workflowName; return; }