Search in sources :

Example 1 with ProcessCall

use of org.compiere.process.ProcessCall in project adempiere by adempiere.

the class ProcessUtil method startJavaProcess.

/**
	 * @param ctx
	 * @param pi
	 * @param trx
	 * @param managedTrx false if trx is managed by caller
	 * @return boolean
	 */
public static boolean startJavaProcess(Properties ctx, ProcessInfo pi, Trx trx, boolean managedTrx) {
    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;
    //use context classloader if available
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader == null)
        classLoader = ProcessUtil.class.getClassLoader();
    try {
        processClass = classLoader.loadClass(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;
    }
    boolean success = false;
    try {
        success = process.startProcess(ctx, pi, trx);
        if (success && trx != null && managedTrx) {
            trx.commit(true);
        }
    } catch (Exception e) {
        pi.setSummary(Msg.getMsg(Env.getCtx(), "ProcessError") + " " + e.getLocalizedMessage(), true);
        log.log(Level.SEVERE, pi.getClassName(), e);
        return false;
    } finally {
        if (trx != null && managedTrx) {
            if (!success)
                trx.rollback();
            trx.close();
            trx = null;
        }
    }
    return success;
}
Also used : MProcess(org.compiere.model.MProcess) ProcessCall(org.compiere.process.ProcessCall)

Aggregations

MProcess (org.compiere.model.MProcess)1 ProcessCall (org.compiere.process.ProcessCall)1