From 2da6fff06e7485d6b36de84a7187768c01b45ca2 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Thu, 13 Dec 2007 07:28:34 +0000 Subject: [PATCH] [ 1846595 ] 2pack do not set the start node in a workflow after import - base on patch submitted by tspc ( Tony ), the update should happen in endElement instead of startElement as the start node haven't been created yet when we want to insert a new workflow record. The original patch would only work if it is a reimport. --- .../pipo/handler/WorkflowElementHandler.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/base/src/org/adempiere/pipo/handler/WorkflowElementHandler.java b/base/src/org/adempiere/pipo/handler/WorkflowElementHandler.java index 354bebcd40..df3cc0daac 100644 --- a/base/src/org/adempiere/pipo/handler/WorkflowElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/WorkflowElementHandler.java @@ -113,6 +113,7 @@ public class WorkflowElementHandler extends AbstractElementHandler { m_Workflow.setAD_WorkflowProcessor_ID(id); } + m_Workflow.setName(workflowName); m_Workflow.setAccessLevel(atts.getValue("AccessLevel")); m_Workflow.setDescription(getStringValue(atts,"Description")); @@ -163,7 +164,42 @@ public class WorkflowElementHandler extends AbstractElementHandler { } } + /** + * @param ctx + * @param element + */ public void endElement(Properties ctx, Element element) throws SAXException { + if (!element.defer && !element.skip && element.recordId > 0) { + Attributes atts = element.attributes; + //set start node + String name = atts.getValue("ADWorkflowNodeNameID"); + if (name != null && name.trim().length() > 0) { + MWorkflow m_Workflow = new MWorkflow(ctx, element.recordId, getTrxName(ctx)); + int id = get_IDWithColumn(ctx, "AD_WF_Node", "Name", name); + if (id <= 0) { + log.warning("Failed to resolve start node reference for workflow element. Workflow=" + + m_Workflow.getName() + " StartNode=" + name); + return; + } + m_Workflow.setAD_WF_Node_ID(id); + if (m_Workflow.save(getTrxName(ctx)) == true) { + log.info("m_Workflow update success"); + record_log(ctx, 1, m_Workflow.getName(), "Workflow", m_Workflow + .get_ID(), 0, "Update", "AD_Workflow", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Workflow")); + workflows.add(m_Workflow.getAD_Workflow_ID()); + element.recordId = m_Workflow.getAD_Workflow_ID(); + } else { + log.info("m_Workflow update fail"); + record_log(ctx, 0, m_Workflow.getName(), "Workflow", m_Workflow + .get_ID(), 0, "Update", "AD_Workflow", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Workflow")); + throw new POSaveFailedException("MWorkflow"); + } + } + } } public void create(Properties ctx, TransformerHandler document)