Search in sources :

Example 1 with RunProcessResponseDocument

use of pl.x3E.adInterface.RunProcessResponseDocument 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)

Example 2 with RunProcessResponseDocument

use of pl.x3E.adInterface.RunProcessResponseDocument in project adempiere by adempiere.

the class ModelADServiceImpl method runProcess.

public RunProcessResponseDocument runProcess(ModelRunProcessRequestDocument req) throws XFireFault {
    RunProcessResponseDocument resbadlogin = RunProcessResponseDocument.Factory.newInstance();
    RunProcessResponse rbadlogin = resbadlogin.addNewRunProcessResponse();
    ModelRunProcess modelRunProcess = req.getModelRunProcessRequest().getModelRunProcess();
    String serviceType = modelRunProcess.getServiceType();
    ADLoginRequest reqlogin = req.getModelRunProcessRequest().getADLoginRequest();
    String err = modelLogin(reqlogin, webServiceName, "runProcess", serviceType);
    if (err != null && err.length() > 0) {
        rbadlogin.setError(err);
        rbadlogin.setIsError(true);
        return resbadlogin;
    }
    // Validate parameters
    modelRunProcess.setADMenuID(validateParameter("AD_Menu_ID", modelRunProcess.getADMenuID()));
    modelRunProcess.setADProcessID(validateParameter("AD_Process_ID", modelRunProcess.getADProcessID()));
    modelRunProcess.setADRecordID(validateParameter("AD_Record_ID", modelRunProcess.getADRecordID()));
    modelRunProcess.setDocAction(validateParameter("DocAction", modelRunProcess.getDocAction()));
    RunProcessDocument docprocess = RunProcessDocument.Factory.newInstance();
    RunProcess reqprocess = docprocess.addNewRunProcess();
    reqprocess.setParamValues(modelRunProcess.getParamValues());
    reqprocess.setADProcessID(modelRunProcess.getADProcessID());
    reqprocess.setADMenuID(modelRunProcess.getADMenuID());
    reqprocess.setADRecordID(modelRunProcess.getADRecordID());
    reqprocess.setDocAction(modelRunProcess.getDocAction());
    return Process.runProcess(m_cs, docprocess);
}
Also used : ModelRunProcess(pl.x3E.adInterface.ModelRunProcess) RunProcessDocument(pl.x3E.adInterface.RunProcessDocument) ADLoginRequest(pl.x3E.adInterface.ADLoginRequest) ModelRunProcess(pl.x3E.adInterface.ModelRunProcess) RunProcess(pl.x3E.adInterface.RunProcess) RunProcessResponse(pl.x3E.adInterface.RunProcessResponse) RunProcessResponseDocument(pl.x3E.adInterface.RunProcessResponseDocument)

Aggregations

RunProcess (pl.x3E.adInterface.RunProcess)2 RunProcessResponse (pl.x3E.adInterface.RunProcessResponse)2 RunProcessResponseDocument (pl.x3E.adInterface.RunProcessResponseDocument)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CharArrayWriter (java.io.CharArrayWriter)1 File (java.io.File)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 JasperPrint (net.sf.jasperreports.engine.JasperPrint)1 MPInstance (org.compiere.model.MPInstance)1 MProcess (org.compiere.model.MProcess)1 MTable (org.compiere.model.MTable)1 PO (org.compiere.model.PO)1 MPrintFormat (org.compiere.print.MPrintFormat)1 ReportEngine (org.compiere.print.ReportEngine)1 ProcessInfo (org.compiere.process.ProcessInfo)1 Trx (org.compiere.util.Trx)1 MWFProcess (org.compiere.wf.MWFProcess)1 MWorkflow (org.compiere.wf.MWorkflow)1 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)1