Search in sources :

Example 16 with MPInstance

use of org.compiere.model.MPInstance in project adempiere by adempiere.

the class ProcessInfoHandler method getProcessInstance.

protected MPInstance getProcessInstance(ProcessInfo info) {
    MPInstance instance = new MPInstance(Env.getCtx(), info.getAD_Process_ID(), info.getRecord_ID());
    if (!instance.save()) {
        info.setSummary(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
        info.setError(true);
        return null;
    }
    return instance;
}
Also used : MPInstance(org.compiere.model.MPInstance)

Example 17 with MPInstance

use of org.compiere.model.MPInstance in project adempiere by adempiere.

the class WProcess method fillParameter.

/**
	 * 	Fill Parameter
	 *	@param request request
	 *	@param process process
	 *	@return process instance
	 */
private MPInstance fillParameter(HttpServletRequest request, MProcess process) {
    MPInstance pInstance = new MPInstance(process, 0);
    //
    MPInstancePara[] iParams = pInstance.getParameters();
    for (int pi = 0; pi < iParams.length; pi++) {
        MPInstancePara iPara = iParams[pi];
        String key = iPara.getParameterName();
        MProcessPara pPara = process.getParameter(key);
        if (pPara == null) {
            log.log(Level.SEVERE, "Parameter not found: " + key);
            continue;
        }
        String valueString = WebUtil.getParameter(request, key);
        log.fine("fillParameter - " + key + " = " + valueString);
        Object value = valueString;
        if (valueString != null && valueString.length() == 0)
            value = null;
        //	No Value
        if (value == null) {
        //	if (pPara.isMandatory())
        //		log.log(Level.WARNING,"fillParameter - " + key 
        //			+ " - empty - mandatory!");
        } else {
            //	Convert to Type
            try {
                if (DisplayType.isNumeric(pPara.getAD_Reference_ID()) || DisplayType.isID(pPara.getAD_Reference_ID())) {
                    BigDecimal bd = null;
                    if (value instanceof BigDecimal)
                        bd = (BigDecimal) value;
                    else if (value instanceof Integer)
                        bd = new BigDecimal(((Integer) value).intValue());
                    else
                        bd = new BigDecimal(value.toString());
                    iPara.setP_Number(bd);
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + bd + "=)");
                } else if (DisplayType.isDate(pPara.getAD_Reference_ID())) {
                    Timestamp ts = null;
                    if (value instanceof Timestamp)
                        ts = (Timestamp) value;
                    else
                        ts = Timestamp.valueOf(value.toString());
                    iPara.setP_Date(ts);
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + ts + "=)");
                } else {
                    iPara.setP_String(value.toString());
                }
                //
                iPara.saveEx();
            } catch (Exception e) {
                log.warning("fillParameter - " + key + " = " + valueString + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
            }
        }
    //	not null
    }
    return pInstance;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) MProcessPara(org.compiere.model.MProcessPara) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 18 with MPInstance

use of org.compiere.model.MPInstance in project adempiere by adempiere.

the class ProcessPanel method loadQuerySaved.

/**
	 * Load Combo
	 */
private void loadQuerySaved() {
    //user query
    List<MPInstance> savedParams = getSavedInstances(true);
    fSavedName.removeAllItems();
    for (MPInstance instance : savedParams) {
        String queries = instance.getName();
        fSavedName.appendItem(queries);
    }
    //	
    fSavedName.setValue("");
}
Also used : MPInstance(org.compiere.model.MPInstance)

Example 19 with MPInstance

use of org.compiere.model.MPInstance in project adempiere by adempiere.

the class WProcessCtl method process.

/**
	 *	Process Control
	 *  <code>
	 *	- Get Instance ID
	 *	- Get Parameters
	 *	- execute (lock - start process - unlock)
	 *  </code>
	 *  Creates a ProcessCtl instance, which calls
	 *  lockUI and unlockUI if parent is a ASyncProcess
	 *  <br>
	 *
	 *  @param aProcess ASyncProcess & Container
	 *  @param WindowNo window no
	 *  @param pi ProcessInfo process info
	 *  @param trx Transaction
	 *  @author Yamel Senih, ysenih@erpcya.com, ERPCyA http://www.erpcya.com
	 *		<li>FR [ 265 ] ProcessParameterPanel is not MVC
	 *		@see https://github.com/adempiere/adempiere/issues/265
	 */
public static void process(ASyncProcess aProcess, int WindowNo, ProcessInfo pi, Trx trx) {
    log.fine("WindowNo=" + WindowNo + " - " + pi);
    MPInstance instance = null;
    try {
        instance = new MPInstance(Env.getCtx(), pi.getAD_Process_ID(), pi.getRecord_ID());
    } catch (Exception e) {
        pi.setSummary(e.getLocalizedMessage());
        pi.setError(true);
        log.warning(pi.toString());
    } catch (Error e) {
        pi.setSummary(e.getLocalizedMessage());
        pi.setError(true);
        log.warning(pi.toString());
    }
    //	Valid null
    if (instance == null)
        return;
    //	
    if (!instance.save()) {
        pi.setSummary(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
        pi.setError(true);
    }
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    //	Get Parameters (Dialog)
    ProcessModalDialog para = new ProcessModalDialog(aProcess, WindowNo, pi);
    if (para.isValid()) {
        para.setWidth("500px");
        para.setVisible(true);
        para.setPosition("center");
        para.setAttribute(Window.MODE_KEY, Window.MODE_MODAL);
        AEnv.showWindow(para);
    }
}
Also used : MPInstance(org.compiere.model.MPInstance)

Example 20 with MPInstance

use of org.compiere.model.MPInstance in project adempiere by adempiere.

the class ProcessCtl method process.

//	execute
/**
	 *	Async Process - Do it all.
	 *  <code>
	 *	- Get Instance ID
	 *	- Get Parameters
	 *	- execute (lock - start process - unlock)
	 *  </code>
	 *  Creates a ProcessCtl instance, which calls
	 *  lockUI and unlockUI if parent is a ASyncProcess
	 *  <br>
	 *	Called from ProcessDialog.actionPerformed
	 *
	 *  @param parent ASyncProcess & Container
	 *  @param WindowNo window no
	 *  @param paraPanel Process Parameter Panel
	 *  @param pi ProcessInfo process info
	 *  @param trx Transaction
	 *  @return worker started ProcessCtl instance or null for workflow
	 */
public static ProcessCtl process(ASyncProcess parent, int WindowNo, ProcessController parameter, ProcessInfo pi, Trx trx) {
    log.fine("WindowNo=" + WindowNo + " - " + pi);
    MPInstance instance = null;
    try {
        instance = new MPInstance(Env.getCtx(), pi.getAD_Process_ID(), pi.getRecord_ID());
    } catch (Exception e) {
        pi.setSummary(e.getLocalizedMessage());
        pi.setError(true);
        log.warning(pi.toString());
        return null;
    } catch (Error e) {
        pi.setSummary(e.getLocalizedMessage());
        pi.setError(true);
        log.warning(pi.toString());
        return null;
    }
    if (!instance.save()) {
        pi.setSummary(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
        pi.setError(true);
        return null;
    }
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    //	BR [ 265 ]
    if (parameter != null) {
        if (parameter.saveParameters() != null) {
            return null;
        }
    }
    //	execute
    ProcessCtl worker = new ProcessCtl(parent, WindowNo, pi, trx);
    if (parent != null) {
        worker.start();
    } else {
        //synchrous
        worker.run();
    }
    return worker;
}
Also used : MPInstance(org.compiere.model.MPInstance) InvalidClassException(java.io.InvalidClassException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Aggregations

MPInstance (org.compiere.model.MPInstance)37 ProcessInfo (org.compiere.process.ProcessInfo)21 MPInstancePara (org.compiere.model.MPInstancePara)19 Trx (org.compiere.util.Trx)12 SQLException (java.sql.SQLException)8 Timestamp (java.sql.Timestamp)8 File (java.io.File)7 AdempiereException (org.adempiere.exceptions.AdempiereException)7 MProcess (org.compiere.model.MProcess)7 IOException (java.io.IOException)6 ReportEngine (org.compiere.print.ReportEngine)6 BigDecimal (java.math.BigDecimal)4 ServletException (javax.servlet.ServletException)4 InvalidClassException (java.io.InvalidClassException)3 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)3 JasperPrint (net.sf.jasperreports.engine.JasperPrint)3 ProcessCtl (org.compiere.apps.ProcessCtl)3 MProcessPara (org.compiere.model.MProcessPara)3 ProcessInfoParameter (org.compiere.process.ProcessInfoParameter)3 PosOrderGlobalVoiding (ar.com.ergio.process.PosOrderGlobalVoiding)2