Search in sources :

Example 11 with MPInstancePara

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

the class ProcessController method updateInstance.

/**
	 * Update a instance from Name
	 * @param saveName
	 * @return
	 */
public String updateInstance(String saveName) {
    //	Validate Instance List
    if (savedParams == null || saveName == null)
        return null;
    //	
    String errorMsg = null;
    try {
        for (MPInstance instance : savedParams) {
            if (instance.getName().equals(saveName)) {
                processInfo.setAD_PInstance_ID(instance.getAD_PInstance_ID());
                for (MPInstancePara para : instance.getParameters()) {
                    para.deleteEx(true);
                }
                //	Save
                errorMsg = saveParameters();
                if (errorMsg != null)
                    throw new AdempiereException(errorMsg);
            }
        }
    } catch (Exception ex) {
        errorMsg = ex.getLocalizedMessage();
        log.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
    //	Default Return
    return errorMsg;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) AdempiereException(org.adempiere.exceptions.AdempiereException) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 12 with MPInstancePara

use of org.compiere.model.MPInstancePara 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 13 with MPInstancePara

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

the class OrderDistribution method generate.

//	saveSelection
public String generate(IStatusBar statusBar, String docActionSelected) {
    String info = "";
    log.info("M_Locator_ID=" + m_M_Locator_ID);
    String trxName = Trx.createTrxName("IMG");
    Trx trx = Trx.get(trxName, true);
    //  prevents from being called twice
    setSelectionActive(false);
    statusBar.setStatusLine(Msg.translate(Env.getCtx(), "M_Movement_ID"));
    statusBar.setStatusDB(String.valueOf(getSelection().size()));
    //	Prepare Process
    int AD_Process_ID = MProcess.getProcess_ID("M_Generate Movement", trxName);
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
    if (!instance.save()) {
        info = Msg.getMsg(Env.getCtx(), "ProcessNoInstance");
        return info;
    }
    DB.createT_Selection(instance.getAD_PInstance_ID(), getSelection(), null);
    //call process
    ProcessInfo pi = new ProcessInfo("VOrderDistribution", AD_Process_ID);
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    //	Add Parameter - Selection=Y
    MPInstancePara ip = new MPInstancePara(instance, 10);
    ip.setParameter("Selection", "Y");
    ip.saveEx();
    MLocator locator = MLocator.get(Env.getCtx(), Integer.parseInt(m_M_Locator_ID.toString()));
    //	Add Parameter - M_Warehouse_ID=x
    ip = new MPInstancePara(instance, 20);
    ip.setParameter("M_Warehouse_ID", locator.getM_Warehouse_ID());
    ip.saveEx();
    setTrx(trx);
    setProcessInfo(pi);
    return info;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) MLocator(org.compiere.model.MLocator) Trx(org.compiere.util.Trx) ProcessInfo(org.compiere.process.ProcessInfo)

Example 14 with MPInstancePara

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

the class MPInstanceTest method testQuery.

public void testQuery() throws Exception {
    lines = new MPInstance(getCtx(), 1000000, getTrxName());
    MPInstancePara[] params = lines.getParameters();
    assertTrue("There should be params", params.length > 0);
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance)

Example 15 with MPInstancePara

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

the class PayrollViaEMail method CreatePDF.

//	sendIndividualMail
private File CreatePDF(int bPartnerId) {
    File attachment = null;
    int AD_Process_ID = reportProcessId;
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, bPartnerId);
    instance.saveEx();
    ProcessInfo pi = new ProcessInfo("PH_SendEmail", AD_Process_ID);
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    //	Add Parameter - Selection=Y
    MPInstancePara ip = new MPInstancePara(instance, 10);
    ip.setParameter(X_HR_Process.COLUMNNAME_HR_Process_ID, payrollProcessId);
    ip.saveEx();
    pi.setRecord_ID(bPartnerId);
    pi.setIsBatch(true);
    MProcess worker = new MProcess(getCtx(), AD_Process_ID, get_TrxName());
    worker.processIt(pi, Trx.get(get_TrxName(), true));
    attachment = pi.getPDFReport();
    return attachment;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) MProcess(org.compiere.model.MProcess) ProcessInfo(org.compiere.process.ProcessInfo) File(java.io.File)

Aggregations

MPInstancePara (org.compiere.model.MPInstancePara)22 MPInstance (org.compiere.model.MPInstance)17 ProcessInfo (org.compiere.process.ProcessInfo)10 Timestamp (java.sql.Timestamp)8 BigDecimal (java.math.BigDecimal)7 Trx (org.compiere.util.Trx)7 SQLException (java.sql.SQLException)4 IOException (java.io.IOException)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MProcessPara (org.compiere.model.MProcessPara)3 File (java.io.File)2 ServletException (javax.servlet.ServletException)2 JasperPrint (net.sf.jasperreports.engine.JasperPrint)2 ProcessCtl (org.compiere.apps.ProcessCtl)2 GridField (org.compiere.model.GridField)2 MProcess (org.compiere.model.MProcess)2 KeyNamePair (org.compiere.util.KeyNamePair)2 Savepoint (java.sql.Savepoint)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1