From bf32da5738da639d24134e1a8c47222ee9fa46e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Tak=C3=A1cs?= <93127072+PeterTakacs300@users.noreply.github.com> Date: Thu, 2 Jun 2022 10:15:39 +0200 Subject: [PATCH] IDEMPIERE-4523 - Process Audit not mark AD_PInstance.IsProcessing on simple Reports (#1343) * IDEMPIERE-4523 - Process Audit not mark AD_PInstance.IsProcessing on simple Reports * IDEMPIERE-4523 - fixed workflow use case --- .../org/compiere/print/ServerReportCtl.java | 71 ++++++++------- .../src/org/compiere/wf/MWFActivity.java | 63 ++++++++------ .../webui/desktop/DashboardController.java | 41 +++++---- .../org/compiere/apps/AbstractProcessCtl.java | 18 ++-- .../src/org/compiere/print/ReportCtl.java | 87 ++++++++++--------- .../org/idempiere/adinterface/Process.java | 6 ++ 6 files changed, 166 insertions(+), 120 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/print/ServerReportCtl.java b/org.adempiere.base/src/org/compiere/print/ServerReportCtl.java index 7fe3e90d6f..d308acf418 100644 --- a/org.adempiere.base/src/org/compiere/print/ServerReportCtl.java +++ b/org.adempiere.base/src/org/compiere/print/ServerReportCtl.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.Properties; import java.util.logging.Level; +import org.compiere.model.MPInstance; import org.compiere.model.MProcess; import org.compiere.model.MQuery; import org.compiere.model.MTable; @@ -217,36 +218,46 @@ public class ServerReportCtl { static public boolean start (ProcessInfo pi) { - /** - * Order Print - */ - if (pi.getAD_Process_ID() == PROCESS_RPT_C_ORDER) // C_Order - return startDocumentPrint(ReportEngine.ORDER, null, pi.getRecord_ID(), null, pi); - if (pi.getAD_Process_ID() == MProcess.getProcess_ID("Rpt PP_Order", null)) // C_Order - return startDocumentPrint(ReportEngine.MANUFACTURING_ORDER, null, pi.getRecord_ID(), null, pi); - if (pi.getAD_Process_ID() == MProcess.getProcess_ID("Rpt DD_Order", null)) // C_Order - return startDocumentPrint(ReportEngine.DISTRIBUTION_ORDER, null, pi.getRecord_ID(), null, pi); - else if (pi.getAD_Process_ID() == PROCESS_RPT_C_INVOICE) // C_Invoice - return startDocumentPrint(ReportEngine.INVOICE, null, pi.getRecord_ID(), null, pi); - else if (pi.getAD_Process_ID() == PROCESS_RPT_M_INOUT) // M_InOut - return startDocumentPrint(ReportEngine.SHIPMENT, null, pi.getRecord_ID(), null, pi); - else if (pi.getAD_Process_ID() == PROCESS_RPT_C_PROJECT) // C_Project - return startDocumentPrint(ReportEngine.PROJECT, null, pi.getRecord_ID(), null, pi); - else if (pi.getAD_Process_ID() == PROCESS_RPT_C_RFQRESPONSE) // C_RfQResponse - return startDocumentPrint(ReportEngine.RFQ, null, pi.getRecord_ID(), null, pi); - else if (pi.getAD_Process_ID() == PROCESS_RPT_C_DUNNING) // Dunning - return startDocumentPrint(ReportEngine.DUNNING, null, pi.getRecord_ID(), null, pi); - else if (pi.getAD_Process_ID() == PROCESS_RPT_FINREPORT // Financial Report - || pi.getAD_Process_ID() == PROCESS_RPT_FINSTATEMENT) // Financial Statement - return startFinReport (pi); - else if (pi.getAD_Process_ID() == PROCESS_RPT_M_INVENTORY) // M_Inventory - return startDocumentPrint(ReportEngine.INVENTORY, null, pi.getRecord_ID(), null, pi); - else if (pi.getAD_Process_ID() == PROCESS_RPT_M_MOVEMENT) // M_Movement - return startDocumentPrint(ReportEngine.MOVEMENT, null, pi.getRecord_ID(), null, pi); - /******************** - * Standard Report - *******************/ - return startStandardReport (pi); + MPInstance instance = new MPInstance(Env.getCtx(), pi.getAD_PInstance_ID(), null); + instance.setIsProcessing(true); + instance.saveEx(); + + try { + /** + * Order Print + */ + if (pi.getAD_Process_ID() == PROCESS_RPT_C_ORDER) // C_Order + return startDocumentPrint(ReportEngine.ORDER, null, pi.getRecord_ID(), null, pi); + if (pi.getAD_Process_ID() == MProcess.getProcess_ID("Rpt PP_Order", null)) // C_Order + return startDocumentPrint(ReportEngine.MANUFACTURING_ORDER, null, pi.getRecord_ID(), null, pi); + if (pi.getAD_Process_ID() == MProcess.getProcess_ID("Rpt DD_Order", null)) // C_Order + return startDocumentPrint(ReportEngine.DISTRIBUTION_ORDER, null, pi.getRecord_ID(), null, pi); + else if (pi.getAD_Process_ID() == PROCESS_RPT_C_INVOICE) // C_Invoice + return startDocumentPrint(ReportEngine.INVOICE, null, pi.getRecord_ID(), null, pi); + else if (pi.getAD_Process_ID() == PROCESS_RPT_M_INOUT) // M_InOut + return startDocumentPrint(ReportEngine.SHIPMENT, null, pi.getRecord_ID(), null, pi); + else if (pi.getAD_Process_ID() == PROCESS_RPT_C_PROJECT) // C_Project + return startDocumentPrint(ReportEngine.PROJECT, null, pi.getRecord_ID(), null, pi); + else if (pi.getAD_Process_ID() == PROCESS_RPT_C_RFQRESPONSE) // C_RfQResponse + return startDocumentPrint(ReportEngine.RFQ, null, pi.getRecord_ID(), null, pi); + else if (pi.getAD_Process_ID() == PROCESS_RPT_C_DUNNING) // Dunning + return startDocumentPrint(ReportEngine.DUNNING, null, pi.getRecord_ID(), null, pi); + else if (pi.getAD_Process_ID() == PROCESS_RPT_FINREPORT // Financial Report + || pi.getAD_Process_ID() == PROCESS_RPT_FINSTATEMENT) // Financial Statement + return startFinReport (pi); + else if (pi.getAD_Process_ID() == PROCESS_RPT_M_INVENTORY) // M_Inventory + return startDocumentPrint(ReportEngine.INVENTORY, null, pi.getRecord_ID(), null, pi); + else if (pi.getAD_Process_ID() == PROCESS_RPT_M_MOVEMENT) // M_Movement + return startDocumentPrint(ReportEngine.MOVEMENT, null, pi.getRecord_ID(), null, pi); + /******************** + * Standard Report + *******************/ + return startStandardReport (pi); + } + finally { + instance.setIsProcessing(false); + instance.saveEx(); + } } // create /************************************************************************** diff --git a/org.adempiere.base/src/org/compiere/wf/MWFActivity.java b/org.adempiere.base/src/org/compiere/wf/MWFActivity.java index 7dd6ddd944..6719eb6bb8 100644 --- a/org.adempiere.base/src/org/compiere/wf/MWFActivity.java +++ b/org.adempiere.base/src/org/compiere/wf/MWFActivity.java @@ -1159,40 +1159,47 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable // Process MProcess process = MProcess.get(getCtx(), m_node.getAD_Process_ID()); MPInstance pInstance = new MPInstance(getCtx(), process.getAD_Process_ID(), getRecord_ID()); + pInstance.setIsProcessing(true); pInstance.saveEx(); - fillParameter(pInstance, trx); - // - ProcessInfo pi = new ProcessInfo (m_node.getName(true), m_node.getAD_Process_ID(), - getAD_Table_ID(), getRecord_ID()); - - //check record id overwrite - MWFNodePara[] nParams = m_node.getParameters(); - for(MWFNodePara p : nParams) - { - if (p.getAD_Process_Para_ID() == 0 && p.getAttributeName().equalsIgnoreCase("Record_ID") && !Util.isEmpty(p.getAttributeValue(), true)) + try { + fillParameter(pInstance, trx); + // + ProcessInfo pi = new ProcessInfo (m_node.getName(true), m_node.getAD_Process_ID(), + getAD_Table_ID(), getRecord_ID()); + + //check record id overwrite + MWFNodePara[] nParams = m_node.getParameters(); + for(MWFNodePara p : nParams) { - try + if (p.getAD_Process_Para_ID() == 0 && p.getAttributeName().equalsIgnoreCase("Record_ID") && !Util.isEmpty(p.getAttributeValue(), true)) { - Object value = parseNodeParaAttribute(p); - if (value == p || value == null) - break; - int recordId = Integer.valueOf(value.toString()); - pi.setRecord_ID(recordId); + try + { + Object value = parseNodeParaAttribute(p); + if (value == p || value == null) + break; + int recordId = Integer.valueOf(value.toString()); + pi.setRecord_ID(recordId); + } + catch (NumberFormatException e) + { + log.log(Level.WARNING, e.getMessage(), e); + } + break; } - catch (NumberFormatException e) - { - log.log(Level.WARNING, e.getMessage(), e); - } - break; } + + pi.setAD_User_ID(getAD_User_ID()); + pi.setAD_Client_ID(getAD_Client_ID()); + pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID()); + boolean success = process.processItWithoutTrxClose(pi, trx); + setTextMsg(pi.getSummary()); + return success; + } + finally { + pInstance.setIsProcessing(false); + pInstance.saveEx(); } - - pi.setAD_User_ID(getAD_User_ID()); - pi.setAD_Client_ID(getAD_Client_ID()); - pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID()); - boolean success = process.processItWithoutTrxClose(pi, trx); - setTextMsg(pi.getSummary()); - return success; } /****** Start Task (Probably redundant; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java index a6ce17e1f4..a94dd2a4d3 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java @@ -869,25 +869,32 @@ public class DashboardController implements EventListener { int AD_Table_ID = 0; int Record_ID = 0; // - MPInstance pInstance = new MPInstance(Env.getCtx(), process.getAD_Process_ID(), Record_ID); + MPInstance pInstance = new MPInstance(process, Record_ID); + pInstance.setIsProcessing(true); pInstance.saveEx(); - fillParameter(pInstance, parameters); - // - ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID(), - AD_Table_ID, Record_ID); - pi.setAD_User_ID(Env.getAD_User_ID(Env.getCtx())); - pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx())); - pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID()); - if (!process.processIt(pi, null) && pi.getClassName() != null) - throw new IllegalStateException("Process failed: (" + pi.getClassName() + ") " + pi.getSummary()); - - // Report - ReportEngine re = ReportEngine.get(Env.getCtx(), pi); - if (re == null) - throw new IllegalStateException("Cannot create Report AD_Process_ID=" + process.getAD_Process_ID() - + " - " + process.getName()); + try { + fillParameter(pInstance, parameters); + // + ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID(), + AD_Table_ID, Record_ID); + pi.setAD_User_ID(Env.getAD_User_ID(Env.getCtx())); + pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx())); + pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID()); + if (!process.processIt(pi, null) && pi.getClassName() != null) + throw new IllegalStateException("Process failed: (" + pi.getClassName() + ") " + pi.getSummary()); + + // Report + ReportEngine re = ReportEngine.get(Env.getCtx(), pi); + if (re == null) + throw new IllegalStateException("Cannot create Report AD_Process_ID=" + process.getAD_Process_ID() + + " - " + process.getName()); + return re; + } + finally { + pInstance.setIsProcessing(false); + pInstance.saveEx(); + } - return re; } public AMedia generateReport(int AD_Process_ID, String parameters) throws Exception { diff --git a/org.adempiere.ui/src/org/compiere/apps/AbstractProcessCtl.java b/org.adempiere.ui/src/org/compiere/apps/AbstractProcessCtl.java index 89fdb47b05..a0ff5e3fdd 100644 --- a/org.adempiere.ui/src/org/compiere/apps/AbstractProcessCtl.java +++ b/org.adempiere.ui/src/org/compiere/apps/AbstractProcessCtl.java @@ -167,13 +167,21 @@ public abstract class AbstractProcessCtl implements Runnable */ if (AD_Workflow_ID > 0) { - startWorkflow (AD_Workflow_ID); MPInstance pinstance = new MPInstance(Env.getCtx(), m_pi.getAD_PInstance_ID(), null); - String errmsg = m_pi.getSummary(); - pinstance.setResult(!m_pi.isError()); - pinstance.setErrorMsg(errmsg); + pinstance.setIsProcessing(true); pinstance.saveEx(); - unlock(); + try { + startWorkflow (AD_Workflow_ID); + String errmsg = m_pi.getSummary(); + pinstance.setResult(!m_pi.isError()); + pinstance.setErrorMsg(errmsg); + pinstance.saveEx(); + unlock(); + } + finally { + pinstance.setIsProcessing(false); + pinstance.saveEx(); + } return; } diff --git a/org.adempiere.ui/src/org/compiere/print/ReportCtl.java b/org.adempiere.ui/src/org/compiere/print/ReportCtl.java index 6c29867535..98cba9161b 100644 --- a/org.adempiere.ui/src/org/compiere/print/ReportCtl.java +++ b/org.adempiere.ui/src/org/compiere/print/ReportCtl.java @@ -136,48 +136,55 @@ public class ReportCtl instance.setAD_PrintFormat_ID(((MPrintFormat)pi.getSerializableObject()).getAD_PrintFormat_ID()); instance.setIsSummary(pi.isSummary()); instance.setAD_Language_ID(pi.getLanguageID()); + instance.setIsProcessing(true); instance.saveEx(); - /** - * Order Print - */ - if (pi.getAD_Process_ID() == PROCESS_RPT_C_ORDER) // C_Order - return startDocumentPrint(ReportEngine.ORDER, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); - if (pi.getAD_Process_ID() == MProcess.getProcess_ID("Rpt PP_Order", null)) // C_Order - return startDocumentPrint(ReportEngine.MANUFACTURING_ORDER, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); - if (pi.getAD_Process_ID() == MProcess.getProcess_ID("Rpt DD_Order", null)) // C_Order - return startDocumentPrint(ReportEngine.DISTRIBUTION_ORDER, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); - else if (pi.getAD_Process_ID() == PROCESS_RPT_C_INVOICE) // C_Invoice - return startDocumentPrint(ReportEngine.INVOICE, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); - else if (pi.getAD_Process_ID() == PROCESS_RPT_M_INOUT) // M_InOut - return startDocumentPrint(ReportEngine.SHIPMENT, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); - else if (pi.getAD_Process_ID() == PROCESS_RPT_C_PROJECT) // C_Project - return startDocumentPrint(ReportEngine.PROJECT, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); - else if (pi.getAD_Process_ID() == PROCESS_RPT_C_RFQRESPONSE) // C_RfQResponse - return startDocumentPrint(ReportEngine.RFQ, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); - else if (pi.getAD_Process_ID() == PROCESS_RPT_C_PAYMENT) // C_Payment - return startCheckPrint(pi.getRecord_ID(), !pi.isPrintPreview()); - else if (pi.getAD_Process_ID() == PROCESS_RPT_M_INVENTORY) // Physical Inventory - return startDocumentPrint(ReportEngine.INVENTORY, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); - else if (pi.getAD_Process_ID() == PROCESS_RPT_M_MOVEMENT) // Inventory Move - return startDocumentPrint(ReportEngine.MOVEMENT, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); - /** - else if (pi.getAD_Process_ID() == 290) // Movement Submission by VHARCQ - return startDocumentPrint(ReportEngine.MOVEMENT, pi.getRecord_ID(), parent, WindowNo, IsDirectPrint); - else if (pi.AD_Process_ID == 9999999) // PaySelection - return startDocumentPrint(CHECK, pi, IsDirectPrint); - else if (pi.AD_Process_ID == 9999999) // PaySelection - return startDocumentPrint(REMITTANCE, pi, IsDirectPrint); - **/ - else if (pi.getAD_Process_ID() == PROCESS_RPT_C_DUNNING) // Dunning - return startDocumentPrint(ReportEngine.DUNNING, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); - else if (pi.getAD_Process_ID() == PROCESS_RPT_FINREPORT // Financial Report - || pi.getAD_Process_ID() == PROCESS_RPT_FINSTATEMENT) // Financial Statement - return startFinReport (pi, WindowNo); - /******************** - * Standard Report - *******************/ - return startStandardReport (pi, WindowNo); + try { + /** + * Order Print + */ + if (pi.getAD_Process_ID() == PROCESS_RPT_C_ORDER) // C_Order + return startDocumentPrint(ReportEngine.ORDER, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); + if (pi.getAD_Process_ID() == MProcess.getProcess_ID("Rpt PP_Order", null)) // C_Order + return startDocumentPrint(ReportEngine.MANUFACTURING_ORDER, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); + if (pi.getAD_Process_ID() == MProcess.getProcess_ID("Rpt DD_Order", null)) // C_Order + return startDocumentPrint(ReportEngine.DISTRIBUTION_ORDER, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); + else if (pi.getAD_Process_ID() == PROCESS_RPT_C_INVOICE) // C_Invoice + return startDocumentPrint(ReportEngine.INVOICE, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); + else if (pi.getAD_Process_ID() == PROCESS_RPT_M_INOUT) // M_InOut + return startDocumentPrint(ReportEngine.SHIPMENT, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); + else if (pi.getAD_Process_ID() == PROCESS_RPT_C_PROJECT) // C_Project + return startDocumentPrint(ReportEngine.PROJECT, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); + else if (pi.getAD_Process_ID() == PROCESS_RPT_C_RFQRESPONSE) // C_RfQResponse + return startDocumentPrint(ReportEngine.RFQ, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); + else if (pi.getAD_Process_ID() == PROCESS_RPT_C_PAYMENT) // C_Payment + return startCheckPrint(pi.getRecord_ID(), !pi.isPrintPreview()); + else if (pi.getAD_Process_ID() == PROCESS_RPT_M_INVENTORY) // Physical Inventory + return startDocumentPrint(ReportEngine.INVENTORY, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); + else if (pi.getAD_Process_ID() == PROCESS_RPT_M_MOVEMENT) // Inventory Move + return startDocumentPrint(ReportEngine.MOVEMENT, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); + /** + else if (pi.getAD_Process_ID() == 290) // Movement Submission by VHARCQ + return startDocumentPrint(ReportEngine.MOVEMENT, pi.getRecord_ID(), parent, WindowNo, IsDirectPrint); + else if (pi.AD_Process_ID == 9999999) // PaySelection + return startDocumentPrint(CHECK, pi, IsDirectPrint); + else if (pi.AD_Process_ID == 9999999) // PaySelection + return startDocumentPrint(REMITTANCE, pi, IsDirectPrint); + **/ + else if (pi.getAD_Process_ID() == PROCESS_RPT_C_DUNNING) // Dunning + return startDocumentPrint(ReportEngine.DUNNING, pi.getRecord_ID(), parent, WindowNo, !pi.isPrintPreview()); + else if (pi.getAD_Process_ID() == PROCESS_RPT_FINREPORT // Financial Report + || pi.getAD_Process_ID() == PROCESS_RPT_FINSTATEMENT) // Financial Statement + return startFinReport (pi, WindowNo); + /******************** + * Standard Report + *******************/ + return startStandardReport (pi, WindowNo); + } + finally { + instance.setIsProcessing(false); + instance.saveEx(); + } } // create /************************************************************************** diff --git a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java index 57801ce181..800b26a887 100644 --- a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java +++ b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java @@ -324,6 +324,8 @@ public class Process { // Start if (process.isWorkflow()) { + pInstance.setIsProcessing(true); + pInstance.saveEx(); try { int AD_Workflow_ID = process.getAD_Workflow_ID(); @@ -345,6 +347,10 @@ public class Process { r.setIsError( true ); return res; } + finally { + pInstance.setIsProcessing(false); + pInstance.saveEx(); + } } if (process.isJavaProcess() && !jasperreport)