diff --git a/base/src/org/adempiere/util/ProcessUtil.java b/base/src/org/adempiere/util/ProcessUtil.java index 64cddf2a56..51687f7918 100644 --- a/base/src/org/adempiere/util/ProcessUtil.java +++ b/base/src/org/adempiere/util/ProcessUtil.java @@ -268,4 +268,79 @@ public final class ProcessUtil { log.fine(pi.toString()); return wfProcess; } + + /** + * Start a java process without closing the given transaction. Is used from the workflow engine. + * @param ctx + * @param pi + * @param trx + * @return + */ + public static boolean startJavaProcessWithoutTrxClose(Properties ctx, ProcessInfo pi, Trx trx) { + String className = pi.getClassName(); + if (className == null) { + MProcess proc = new MProcess(ctx, pi.getAD_Process_ID(), trx.getTrxName()); + if (proc.getJasperReport() != null) + className = JASPER_STARTER_CLASS; + } + //Get Class + Class processClass = null; + try + { + processClass = Class.forName (className); + } + catch (ClassNotFoundException ex) + { + log.log(Level.WARNING, className, ex); + pi.setSummary ("ClassNotFound", true); + return false; + } + + //Get Process + ProcessCall process = null; + try + { + process = (ProcessCall)processClass.newInstance(); + } + catch (Exception ex) + { + log.log(Level.WARNING, "Instance for " + className, ex); + pi.setSummary ("InstanceError", true); + return false; + } + + if (processClass == null) { + pi.setSummary("No Instance for " + pi.getClassName(), true); + return false; + } + + try + { + boolean success = process.startProcess(ctx, pi, trx); + if (trx != null) + { + if(success){ +// + } else { + trx.rollback(); + trx.close(); + return false; + } + } + } + catch (Exception e) + { + if (trx != null) + { + trx.rollback(); + trx.close(); + } + pi.setSummary("ProcessError", true); + log.log(Level.SEVERE, pi.getClassName(), e); + return false; + } + return true; + } + + } \ No newline at end of file diff --git a/base/src/org/compiere/model/MProcess.java b/base/src/org/compiere/model/MProcess.java index d175eb8730..b25b0448b9 100644 --- a/base/src/org/compiere/model/MProcess.java +++ b/base/src/org/compiere/model/MProcess.java @@ -423,5 +423,68 @@ public class MProcess extends X_AD_Process } } + /** + * Process It without closing the given transaction - used from workflow engine. + * @param pi Process Info + * @param trx transaction + * @return true if OK + */ + public boolean processItWithoutTrxClose (ProcessInfo pi, Trx trx) + { + if (pi.getAD_PInstance_ID() == 0) + { + MPInstance pInstance = new MPInstance (this, pi.getRecord_ID()); + // Lock + pInstance.setIsProcessing(true); + pInstance.save(); + } + + boolean ok = false; + + // Java Class + String Classname = getClassname(); + if (Classname != null && Classname.length() > 0) + { + pi.setClassName(Classname); + ok = startClassWithoutTrxClose(pi, trx); + } + else + { + // PL/SQL Procedure + String ProcedureName = getProcedureName(); + if (ProcedureName != null && ProcedureName.length() > 0) + { + ok = startProcess (ProcedureName, pi, trx); + } + else + { + String msg = "No Classname or ProcedureName for " + getName(); + pi.setSummary(msg, ok); + log.warning(msg); + } + } + + return ok; + } // processItWithoutTrxClose + + /** + * Start Java Class (sync) without closing the given transaction. + * instanciate the class implementing the interface ProcessCall. + * The class can be a Server/Client class (when in Package + * org adempiere.process or org.compiere.model) or a client only class + * (e.g. in org.compiere.report) + * + * @param Classname name of the class to call + * @param pi process info + * @param trx transaction + * @return true if success + * see ProcessCtl.startClass + */ + private boolean startClassWithoutTrxClose (ProcessInfo pi, Trx trx) + { + log.info(pi.getClassName()); + return ProcessUtil.startJavaProcessWithoutTrxClose(getCtx(), pi, trx); + } // startClassWithoutTrxClose + } // MProcess diff --git a/base/src/org/compiere/wf/MWFActivity.java b/base/src/org/compiere/wf/MWFActivity.java index 402133def0..9a193eb6a7 100644 --- a/base/src/org/compiere/wf/MWFActivity.java +++ b/base/src/org/compiere/wf/MWFActivity.java @@ -985,7 +985,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable pi.setAD_User_ID(getAD_User_ID()); pi.setAD_Client_ID(getAD_Client_ID()); pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID()); - return process.processIt(pi, trx); + return process.processItWithoutTrxClose(pi, trx); } /****** Start Task (Probably redundant;