Search in sources :

Example 1 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 2 with MPInstancePara

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

the class MWFActivity method fillParameter.

//	setUserConfirmation
/**
	 * 	Fill Parameter
	 *	@param pInstance process instance
	 * 	@param trx transaction
	 */
private void fillParameter(MPInstance pInstance, Trx trx) {
    getPO(trx);
    //
    MWFNodePara[] nParams = m_node.getParameters();
    MPInstancePara[] iParams = pInstance.getParameters();
    for (int pi = 0; pi < iParams.length; pi++) {
        MPInstancePara iPara = iParams[pi];
        for (int np = 0; np < nParams.length; np++) {
            MWFNodePara nPara = nParams[np];
            if (iPara.getParameterName().equals(nPara.getAttributeName())) {
                String variableName = nPara.getAttributeValue();
                log.fine(nPara.getAttributeName() + " = " + variableName);
                //	Value - Constant/Variable
                Object value = variableName;
                if (variableName == null || (variableName != null && variableName.length() == 0))
                    value = null;
                else if (//	we have a variable
                variableName.indexOf('@') != -1 && m_po != null) {
                    //	Strip
                    int index = variableName.indexOf('@');
                    String columnName = variableName.substring(index + 1);
                    index = columnName.indexOf('@');
                    if (index == -1) {
                        log.warning(nPara.getAttributeName() + " - cannot evaluate=" + variableName);
                        break;
                    }
                    columnName = columnName.substring(0, index);
                    index = m_po.get_ColumnIndex(columnName);
                    if (index != -1) {
                        value = m_po.get_Value(index);
                    } else //	not a column
                    {
                        //	try Env
                        String env = Env.getContext(getCtx(), columnName);
                        if (env.length() == 0) {
                            log.warning(nPara.getAttributeName() + " - not column nor environment =" + columnName + "(" + variableName + ")");
                            break;
                        } else
                            value = env;
                    }
                }
                //	No Value
                if (value == null) {
                    if (nPara.isMandatory())
                        log.warning(nPara.getAttributeName() + " - empty - mandatory!");
                    else
                        log.fine(nPara.getAttributeName() + " - empty");
                    break;
                }
                //	Convert to Type
                try {
                    if (DisplayType.isNumeric(nPara.getDisplayType()) || DisplayType.isID(nPara.getDisplayType())) {
                        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(nPara.getAttributeName() + " = " + variableName + " (=" + bd + "=)");
                    } else if (DisplayType.isDate(nPara.getDisplayType())) {
                        Timestamp ts = null;
                        if (value instanceof Timestamp)
                            ts = (Timestamp) value;
                        else
                            ts = Timestamp.valueOf(value.toString());
                        iPara.setP_Date(ts);
                        log.fine(nPara.getAttributeName() + " = " + variableName + " (=" + ts + "=)");
                    } else {
                        iPara.setP_String(value.toString());
                        log.fine(nPara.getAttributeName() + " = " + variableName + " (=" + value + "=) " + value.getClass().getName());
                    }
                    if (!iPara.save())
                        log.warning("Not Saved - " + nPara.getAttributeName());
                } catch (Exception e) {
                    log.warning(nPara.getAttributeName() + " = " + variableName + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
                }
                break;
            }
        }
    //	node parameter loop
    }
//	instance parameter loop
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) Timestamp(java.sql.Timestamp) Savepoint(java.sql.Savepoint) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 3 with MPInstancePara

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

the class VInOutInvoiceGen method generateInvoices.

//  generateShipments_complete
/**************************************************************************
	 *	Generate Invoices
	 */
private void generateInvoices() {
    String trxName = Trx.createTrxName("IVG");
    //trx needs to be committed too
    Trx trx = Trx.get(trxName, true);
    //String trxName = null;
    //Trx trx = null;
    //  prevents from being called twice
    m_selectionActive = false;
    statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InvGenerateGen"));
    statusBar.setStatusDB(String.valueOf(selection.size()));
    //	Prepare Process
    int AD_Process_ID = 0;
    KeyNamePair docTypeKNPair = (KeyNamePair) cmbDocType.getSelectedItem();
    if (docTypeKNPair.getKey() == MRMA.Table_ID) {
        // C_Invoice_GenerateRMA - org.adempiere.process.InvoiceGenerateRMA
        AD_Process_ID = 52002;
    } else {
        // HARDCODED    C_InvoiceCreate
        AD_Process_ID = 134;
    }
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
    if (!instance.save()) {
        info.setText(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
        return;
    }
    //insert selection
    /*Selection exist from shipment*/
    StringBuffer insert = new StringBuffer();
    insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
    int counter = 0;
    for (Integer selectedId : selection) {
        counter++;
        if (counter > 1)
            insert.append(" UNION ");
        insert.append("SELECT ");
        insert.append(instance.getAD_PInstance_ID());
        insert.append(", ");
        insert.append(selectedId);
        insert.append(" FROM DUAL ");
        if (counter == 1000) {
            if (DB.executeUpdate(insert.toString(), trxName) < 0) {
                //  not translated!
                String msg = "No Shipments";
                log.config(msg);
                info.setText(msg);
                trx.rollback();
                return;
            }
            insert = new StringBuffer();
            insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
            counter = 0;
        }
    }
    if (counter > 0) {
        if (DB.executeUpdate(insert.toString(), trxName) < 0) {
            //  not translated!
            String msg = "No Shipments";
            log.config(msg);
            info.setText(msg);
            trx.rollback();
            return;
        }
    }
    ProcessInfo pi = new ProcessInfo("", AD_Process_ID);
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    //	Add Parameters
    MPInstancePara para = new MPInstancePara(instance, 10);
    para.setParameter("Selection", "Y");
    if (!para.save()) {
        //  not translated
        String msg = "No Selection Parameter added";
        info.setText(msg);
        log.log(Level.SEVERE, msg);
        return;
    }
    para = new MPInstancePara(instance, 20);
    para.setParameter("DocAction", "CO");
    if (!para.save()) {
        //  not translated
        String msg = "No DocAction Parameter added";
        info.setText(msg);
        log.log(Level.SEVERE, msg);
        return;
    }
    //	Execute Process
    ProcessCtl worker = new ProcessCtl(this, Env.getWindowNo(this), pi, trx);
    //  complete tasks in unlockUI / generateInvoice_complete
    worker.start();
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) ProcessCtl(org.compiere.apps.ProcessCtl) Trx(org.compiere.util.Trx) KeyNamePair(org.compiere.util.KeyNamePair) ProcessInfo(org.compiere.process.ProcessInfo)

Example 4 with MPInstancePara

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

the class VInOutInvoiceGen method generateShipments.

//	saveSelection
/**************************************************************************
	 *	Generate Shipments
	 */
private void generateShipments() {
    log.info("M_Warehouse_ID=" + m_M_Warehouse_ID);
    String trxName = Trx.createTrxName("IOG");
    //trx needs to be committed too
    Trx trx = Trx.get(trxName, true);
    //String trxName = null;
    //Trx trx = null;
    //  prevents from being called twice
    m_selectionActive = false;
    statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InOutGenerateGen"));
    statusBar.setStatusDB(String.valueOf(selection.size()));
    //	Prepare Process
    int AD_Process_ID = 0;
    KeyNamePair docTypeKNPair = (KeyNamePair) cmbDocType.getSelectedItem();
    if (docTypeKNPair.getKey() == MRMA.Table_ID) {
        // M_InOut_GenerateRMA - org.adempiere.process.InOutGenerateRMA
        AD_Process_ID = 52001;
    } else {
        // M_InOut_Generate - org.compiere.process.InOutGenerate
        AD_Process_ID = 199;
    }
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
    if (!instance.save()) {
        info.setText(Msg.getMsg(Env.getCtx(), "ProcessNoInstance"));
        return;
    }
    //insert selection
    StringBuffer insert = new StringBuffer();
    insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
    int counter = 0;
    for (Integer selectedId : selection) {
        counter++;
        if (counter > 1)
            insert.append(" UNION ");
        insert.append("SELECT ");
        insert.append(instance.getAD_PInstance_ID());
        insert.append(", ");
        insert.append(selectedId);
        insert.append(" FROM DUAL ");
        if (counter == 1000) {
            if (DB.executeUpdate(insert.toString(), trxName) < 0) {
                //  not translated!
                String msg = "No Shipments";
                log.config(msg);
                info.setText(msg);
                trx.rollback();
                return;
            }
            insert = new StringBuffer();
            insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
            counter = 0;
        }
    }
    if (counter > 0) {
        if (DB.executeUpdate(insert.toString(), trxName) < 0) {
            //  not translated!
            String msg = "No Shipments";
            log.config(msg);
            info.setText(msg);
            trx.rollback();
            return;
        }
    }
    //call process
    ProcessInfo pi = new ProcessInfo("VInOutGen", 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");
    if (!ip.save()) {
        //  not translated
        String msg = "No Parameter added";
        info.setText(msg);
        log.log(Level.SEVERE, msg);
        return;
    }
    //	Add Parameter - M_Warehouse_ID=x
    ip = new MPInstancePara(instance, 20);
    ip.setParameter("M_Warehouse_ID", Integer.parseInt(m_M_Warehouse_ID.toString()));
    if (!ip.save()) {
        //  not translated
        String msg = "No Parameter added";
        info.setText(msg);
        log.log(Level.SEVERE, msg);
        return;
    }
    //	Execute Process
    ProcessCtl worker = new ProcessCtl(this, Env.getWindowNo(this), pi, trx);
    //  complete tasks in unlockUI / generateShipments_complete
    worker.start();
//
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) ProcessCtl(org.compiere.apps.ProcessCtl) Trx(org.compiere.util.Trx) KeyNamePair(org.compiere.util.KeyNamePair) ProcessInfo(org.compiere.process.ProcessInfo)

Example 5 with MPInstancePara

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

the class Process method fillParameter.

//	createProcessPage
private static MPInstance fillParameter(CompiereService m_cs, DataRow dr, MProcess process) throws Exception {
    MPInstance pInstance = new MPInstance(process, 0);
    DataField[] f = dr.getFieldArray();
    HashMap fmap = new HashMap();
    for (int i = 0; i < f.length; i++) fmap.put(f[i].getColumn(), f[i].getVal());
    //
    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;
        }
        int displayType = pPara.getAD_Reference_ID();
        String valueString = null;
        Object ob = fmap.get(key);
        if (ob != null)
            valueString = ob.toString();
        String valueString2 = null;
        if (pPara.isRange()) {
            ob = fmap.get(key + "_2");
            if (ob != null)
                valueString2 = ob.toString();
        }
        log.fine("fillParameter - " + key + " = " + valueString);
        Object value = valueString;
        if (valueString != null && valueString.length() == 0)
            value = null;
        if (value != null && (DisplayType.List == displayType || DisplayType.TableDir == displayType || DisplayType.Table == displayType) && value.equals("-1"))
            value = null;
        //	No Value
        if (value == null && DisplayType.YesNo != pPara.getAD_Reference_ID()) {
            if (pPara.isMandatory())
                throw new Exception(" Parameter " + pPara.getName() + " is required.");
        } else {
            //	Convert to Type
            try {
                if (DisplayType.isNumeric(displayType) || DisplayType.isID(displayType)) {
                    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 + "=)");
                    if (pPara.isRange()) {
                        bd = null;
                        bd = new BigDecimal(valueString2.toString());
                        iPara.setP_Number_To(bd);
                    }
                } else if (DisplayType.isDate(displayType)) {
                    java.util.Date d;
                    if (displayType == DisplayType.DateTime)
                        d = m_cs.dateFormat.parse(value.toString());
                    else
                        // TODO: datetime
                        d = m_cs.dateFormat.parse(value.toString());
                    //d = m_cs.dateTimeFormat.parse(value.toString());
                    Timestamp ts = null;
                    ts = new Timestamp(d.getTime());
                    iPara.setP_Date(ts);
                    if (pPara.isRange()) {
                        if (displayType == DisplayType.DateTime)
                            d = m_cs.dateFormat.parse(valueString2);
                        else //d = m_cs.dateTimeFormat.parse(valueString2);
                        {
                            if (valueString2 == null || valueString2.length() == 0)
                                d = new java.util.Date();
                            else
                                //TODO: datetime
                                d = m_cs.dateFormat.parse(valueString2);
                        }
                        ts = new Timestamp(d.getTime());
                        iPara.setP_Date_To(ts);
                    }
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + ts + "=)");
                } else if (DisplayType.YesNo == pPara.getAD_Reference_ID()) {
                    String bv = "N";
                    if (value == null)
                        bv = "N";
                    else //if (value.toString().toLowerCase().charAt(0)=='t')
                    {
                        if ("true".equalsIgnoreCase(valueString) || "y".equalsIgnoreCase(valueString))
                            bv = "Y";
                        else
                            bv = "N";
                    }
                    //bv ="Y";
                    iPara.setP_String(bv);
                } else {
                    iPara.setP_String(value.toString());
                }
                if (// kolec - ustawia wartosc dla parametru Lookup
                pPara.isLookup()) {
                    Lookup lok = pPara.getLookup();
                    if (lok != null) {
                        NamePair np = lok.getDirect(value, false, false);
                        if (np != null) {
                            iPara.setInfo(np.getName());
                        }
                    }
                } else {
                    if (value != null)
                        iPara.setInfo(value.toString());
                    if (valueString2 != null)
                        iPara.setInfo_To(valueString2);
                }
                //
                iPara.save();
            } catch (Exception e) {
                log.warning("fillParameter - " + key + " = " + valueString + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
            }
        }
    //	not null
    }
    //	instance parameter loop
    // kolec - tego chyba brakowalo
    pInstance.save();
    return pInstance;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) HashMap(java.util.HashMap) NamePair(org.compiere.util.NamePair) MProcessPara(org.compiere.model.MProcessPara) Timestamp(java.sql.Timestamp) JasperPrint(net.sf.jasperreports.engine.JasperPrint) SQLException(java.sql.SQLException) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) MPInstance(org.compiere.model.MPInstance) DataField(pl.x3E.adInterface.DataField) Lookup(org.compiere.model.Lookup)

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