Search in sources :

Example 16 with PO

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

the class POWrapper method refresh.

/**
	 * Reload underlying PO object in same transaction as it was
	 * 
	 * @param model
	 * @see #refresh(Object, String)
	 * @throws IllegalArgumentException if model is null
	 * @throws IllegalArgumentException if there is no underlying PO object (i.e. getPO(model) return null)
	 */
public static void refresh(Object model) {
    if (model == null)
        throw new IllegalArgumentException("model is null");
    final PO po = getPO(model);
    if (po == null)
        throw new IllegalArgumentException("Class is not supported - " + model.getClass());
    po.load(po.get_TrxName());
}
Also used : PO(org.compiere.model.PO)

Example 17 with PO

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

the class InterfaceWrapperHelper method getValue.

private static <T> T getValue(final Object model, final String columnName, final boolean throwExIfColumnNotFound) {
    Check.assumeNotNull(model, "model is not null");
    Check.assumeNotNull(columnName, "columnName is not null");
    if (GridTabWrapper.isHandled(model)) {
        final GridTab gridTab = GridTabWrapper.getGridTab(model);
        final GridField gridField = gridTab.getField(columnName);
        if (gridField == null) {
            if (throwExIfColumnNotFound) {
                throw new AdempiereException("No field with ColumnName=" + columnName + " found in " + gridTab + " for " + model);
            } else {
                return null;
            }
        }
        @SuppressWarnings("unchecked") final T value = (T) gridField.getValue();
        return value;
    } else if (POWrapper.isHandled(model)) {
        PO po = POWrapper.getPO(model, false);
        final int idx = po.get_ColumnIndex(columnName);
        if (idx < 0) {
            if (throwExIfColumnNotFound) {
                throw new AdempiereException("No columnName " + columnName + " found for " + model);
            } else {
                return null;
            }
        }
        @SuppressWarnings("unchecked") T value = (T) po.get_Value(idx);
        return value;
    } else {
        throw new AdempiereException("Model wrapping is not supported for " + model + " (class:" + model.getClass() + ")");
    }
}
Also used : GridTab(org.compiere.model.GridTab) AdempiereException(org.adempiere.exceptions.AdempiereException) GridField(org.compiere.model.GridField) PO(org.compiere.model.PO)

Example 18 with PO

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

the class MWFActivity method getAttributeValue.

//	getPO_AD_Client_ID
/**
	 * 	Get Attribute Value (based on Node) of PO
	 *	@return Attribute Value or null
	 */
public Object getAttributeValue() {
    MWFNode node = getNode();
    if (node == null)
        return null;
    int AD_Column_ID = node.getAD_Column_ID();
    if (AD_Column_ID == 0)
        return null;
    PO po = getPO();
    if (po.get_ID() == 0)
        return null;
    return po.get_ValueOfColumn(AD_Column_ID);
}
Also used : Savepoint(java.sql.Savepoint) PO(org.compiere.model.PO)

Example 19 with PO

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

the class MWFNextCondition method evaluate.

//	isOr
/**
	 * 	Evaluate Condition
	 * 	@param activity activity
	 *	@return true if true
	 */
public boolean evaluate(MWFActivity activity) {
    if (getAD_Column_ID() == 0)
        throw new IllegalStateException("No Column defined - " + this);
    PO po = activity.getPO();
    if (po == null || po.get_ID() == 0)
        throw new IllegalStateException("Could not evaluate " + po + " - " + this);
    //
    Object valueObj = po.get_ValueOfColumn(getAD_Column_ID());
    if (valueObj == null)
        valueObj = "";
    // F3P: added value decoding
    String value1 = getDecodedValue(getValue(), po);
    if (value1 == null)
        value1 = "";
    // F3P: added value decoding
    String value2 = getDecodedValue(getValue2(), po);
    if (value2 == null)
        value2 = "";
    String resultStr = "PO:{" + valueObj + "} " + getOperation() + " Condition:{" + value1 + "}";
    if (getOperation().equals(OPERATION_Sql))
        throw new IllegalArgumentException("SQL Operator not implemented yet: " + resultStr);
    if (getOperation().equals(OPERATION_X))
        resultStr += "{" + value2 + "}";
    boolean result = false;
    if (valueObj instanceof Number)
        result = compareNumber((Number) valueObj, value1, value2);
    else if (valueObj instanceof Boolean)
        result = compareBoolean((Boolean) valueObj, value1, value2);
    else
        result = compareString(valueObj, value1, value2);
    //
    log.fine(resultStr + " -> " + result + (m_numeric ? " (#)" : " ($)"));
    return result;
}
Also used : PO(org.compiere.model.PO)

Example 20 with PO

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

the class Process method runProcess.

/**************************************************************************
	 * 	Create Process Page
	 *	@param AD_Process_ID Process
	 *	@return Page
	 */
public static RunProcessResponseDocument runProcess(CompiereService m_cs, RunProcessDocument req) {
    RunProcessResponseDocument res = RunProcessResponseDocument.Factory.newInstance();
    RunProcessResponse r = res.addNewRunProcessResponse();
    RunProcess rp = req.getRunProcess();
    int AD_Process_ID = rp.getADProcessID();
    int m_record_id = rp.getADRecordID();
    //WebSessionCtx wsc = WebSessionCtx.get (request);
    MProcess process = MProcess.get(m_cs.getM_ctx(), AD_Process_ID);
    //	need to check if Role can access
    if (process == null) {
        // WebDoc doc = WebDoc.createWindow("Process not found");
        r.setError("Process not found");
        r.setIsError(true);
        return res;
    }
    //process.getDescription()
    //process.getHelp()
    // Evaluate DocAction, if call have DocAction parameter, then try to set DocAction before calling workflow process
    String docAction = rp.getDocAction();
    if (docAction != null && docAction.length() > 0) {
        // - the process must be a workflow document
        if (process.getAD_Workflow_ID() > 0) {
            MWorkflow wf = MWorkflow.get(m_cs.getM_ctx(), process.getAD_Workflow_ID());
            if (wf.getWorkflowType().equals(MWorkflow.WORKFLOWTYPE_DocumentProcess)) {
                // - get the table associated with the workflow document
                // - set DocAction in such table
                // get the PO for the tablename and record ID
                MTable table = MTable.get(m_cs.getM_ctx(), wf.getAD_Table_ID());
                if (table != null) {
                    PO po = table.getPO(m_record_id, null);
                    if (po != null) {
                        po.set_ValueOfColumn("DocAction", docAction);
                        po.save();
                    }
                }
            }
        }
    }
    //	Create Process Instance
    MPInstance pInstance = null;
    try {
        pInstance = fillParameter(m_cs, rp.getParamValues(), process);
    } catch (Exception ex) {
        //center.addElement(new p("B��d: " + ex.getMessage(), AlignType.LEFT).setClass("ProcesResultError"));
        r.setError(ex.getMessage());
        r.setIsError(true);
        return res;
    }
    if (m_record_id > 0) {
        pInstance.setRecord_ID(m_record_id);
        pInstance.save();
    }
    //
    ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID());
    pi.setAD_User_ID(Env.getAD_User_ID(m_cs.getM_ctx()));
    pi.setAD_Client_ID(Env.getAD_Client_ID(m_cs.getM_ctx()));
    pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
    if (m_record_id > 0)
        pi.setRecord_ID(m_record_id);
    //	Info
    //p p = new p();
    //p.addElement(Msg.translate(wsc.ctx, "AD_PInstance_ID") + ": " + pInstance.getAD_PInstance_ID());
    //center.addElement(p);
    boolean processOK = false;
    boolean jasperreport = (process != null && process.getClassname() != null && process.getClassname().indexOf("net.sf.compilo.report.ReportStarter") >= 0);
    if (jasperreport) {
        //this.jasperReport( request, response, wsc.ctx, pi);
        processOK = true;
    }
    //	Start
    if (process.isWorkflow()) {
        try {
            int AD_Workflow_ID = process.getAD_Workflow_ID();
            MWorkflow wf = MWorkflow.get(Env.getCtx(), AD_Workflow_ID);
            //	may return null
            MWFProcess wfProcess = wf.startWait(pi);
            if (wfProcess != null) {
                //wynik
                r.setSummary(pi.getSummary());
                r.setLogInfo(pi.getLogInfo(true));
                r.setIsError(false);
                return res;
            }
        } catch (Exception ex) {
            r.setError(ex.getMessage());
            r.setLogInfo(pi.getLogInfo(true));
            r.setIsError(true);
            return res;
        //Wyj�tek: pi.getLogInfo(true) pi.getLogInfo(true)
        }
    //started = wfProcess != null;
    }
    if (process.isJavaProcess() && !jasperreport) {
        Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
        try {
            processOK = process.processIt(pi, trx);
            trx.commit();
            trx.close();
        } catch (Throwable t) {
            trx.rollback();
            trx.close();
        }
        if (!processOK || pi.isError()) {
            // b��d:  pi.getSummary()
            r.setSummary(pi.getSummary());
            r.setLogInfo(pi.getLogInfo(true));
            r.setIsError(true);
            processOK = false;
        } else {
            r.setSummary(pi.getSummary());
            r.setLogInfo(pi.getLogInfo(true));
            r.setIsError(false);
        //return res;	
        // wynik - String summary = pi.getSummary();
        }
    }
    //	Report
    if (//&& !m_jasperreport)
    (process.isReport() || jasperreport)) /*processOK &&*/
    {
        r.setIsReport(true);
        //if (m_jasperreport)
        //{
        //	center.addElement(new p("JASPER REPORT", AlignType.LEFT).setClass("Cerror"));
        //} 
        //else
        {
            ReportEngine re = null;
            if (!jasperreport)
                re = start(pi);
            //ReportEngine.get(m_cs.getM_ctx(), pi);
            if (re == null && !jasperreport) {
            //b��d: "Nie uda�o si� uruchomi� silnika raport�w (ReportEngine)", 
            } else {
                try {
                    boolean ok = false;
                    File file;
                    String file_type = "pdf";
                    if (!jasperreport) {
                        //file = File.createTempFile("WProcess", ".pdf");
                        //ok = re.createPDF(file);
                        MPrintFormat pf = re.getPrintFormat();
                        if (pf.isTableBased()) {
                            CharArrayWriter wr = new CharArrayWriter();
                            //file = File.createTempFile("WProcess", ".xls");
                            ok = ReportEngineEx.createEXCEL_HTML_wr(re, m_cs.getM_ctx(), wr, false, re.getPrintFormat().getLanguage());
                            //ok = re.createXML( file );
                            file_type = "xls";
                            String data = wr.toString();
                            if (data != null)
                                r.setData(data.getBytes());
                            r.setReportFormat(file_type);
                        } else {
                            byte[] dat = re.createPDFData();
                            file_type = "pdf";
                            r.setData(dat);
                            r.setReportFormat(file_type);
                        }
                        //r.setReportFormat("xls");							
                        ok = true;
                    } else {
                        JasperPrint jp = getJasperReportPrint(m_cs.getM_ctx(), pi);
                        //file = File.createTempFile("WProcess", ".pdf");
                        ByteArrayOutputStream wr = new ByteArrayOutputStream();
                        net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jp, wr);
                        //exportReportToPdfFile( jp, file.getAbsolutePath() );							
                        file_type = "pdf";
                        r.setData(wr.toByteArray());
                        r.setReportFormat(file_type);
                        ok = true;
                    }
                    if (ok) {
                        //pInstance.getAD_PInstance_ID()
                        //file.getAbsolutePath()
                        //	Marker that Process is OK
                        m_cs.getM_ctx().put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
                    } else {
                        r.setError("Cannot create report");
                        r.setLogInfo(pi.getLogInfo(true));
                        r.setIsError(true);
                        return res;
                    //"Cannot create report:",
                    }
                } catch (Exception e) {
                    r.setError("Cannot create report:" + e.getMessage());
                    r.setLogInfo(pi.getLogInfo(true));
                    r.setIsError(true);
                    return res;
                // , 
                }
            }
        }
    }
    return res;
}
Also used : MProcess(org.compiere.model.MProcess) MWFProcess(org.compiere.wf.MWFProcess) MWorkflow(org.compiere.wf.MWorkflow) JasperPrint(net.sf.jasperreports.engine.JasperPrint) ProcessInfo(org.compiere.process.ProcessInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunProcessResponse(pl.x3E.adInterface.RunProcessResponse) JasperPrint(net.sf.jasperreports.engine.JasperPrint) SQLException(java.sql.SQLException) IOException(java.io.IOException) CharArrayWriter(java.io.CharArrayWriter) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) MPrintFormat(org.compiere.print.MPrintFormat) MTable(org.compiere.model.MTable) RunProcess(pl.x3E.adInterface.RunProcess) Trx(org.compiere.util.Trx) File(java.io.File) RunProcessResponseDocument(pl.x3E.adInterface.RunProcessResponseDocument) PO(org.compiere.model.PO)

Aggregations

PO (org.compiere.model.PO)75 MTable (org.compiere.model.MTable)18 AdempiereException (org.adempiere.exceptions.AdempiereException)17 SQLException (java.sql.SQLException)16 Properties (java.util.Properties)13 BigDecimal (java.math.BigDecimal)11 Query (org.compiere.model.Query)8 Element (org.w3c.dom.Element)7 ArrayList (java.util.ArrayList)6 MEXPFormat (org.compiere.model.MEXPFormat)6 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)6 POInfo (org.compiere.model.POInfo)5 Trx (org.compiere.util.Trx)5 ModelCRUD (pl.x3E.adInterface.ModelCRUD)5 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 XFireFault (org.codehaus.xfire.fault.XFireFault)4 DataField (pl.x3E.adInterface.DataField)4 DataRow (pl.x3E.adInterface.DataRow)4 ParseException (java.text.ParseException)3