Search in sources :

Example 51 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class VCreateFromInvoiceUI method init.

//  infoStatement
@Override
public void init(int WindowNo, FormFrame frame) {
    p_WindowNo = WindowNo;
    v_Container = frame;
    ProcessInfo info = frame.getProcessInfo();
    try {
        //	Valid for launched from a window
        if (info != null) {
            //	Valid Table and Record
            validTable(info.getTable_ID(), info.getRecord_ID());
        }
        //	Init
        if (!dynInit())
            return;
        jbInit();
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
}
Also used : ProcessInfo(org.compiere.process.ProcessInfo)

Example 52 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class VCreateFromRMAUI method init.

@Override
public void init(int WindowNo, FormFrame frame) {
    p_WindowNo = WindowNo;
    v_Container = frame;
    ProcessInfo info = frame.getProcessInfo();
    try {
        //	Valid for launched from a window
        if (info != null) {
            //	Valid Table and Record
            validTable(info.getTable_ID(), info.getRecord_ID());
        }
        //	Init
        if (!dynInit())
            return;
        jbInit();
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
}
Also used : ProcessInfo(org.compiere.process.ProcessInfo)

Example 53 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class VCreateFromShipmentUI method init.

@Override
public void init(int WindowNo, FormFrame frame) {
    p_WindowNo = WindowNo;
    v_Container = frame;
    ProcessInfo info = frame.getProcessInfo();
    try {
        //	Valid for launched from a window
        if (info != null) {
            //	Valid Table and Record
            validTable(info.getTable_ID(), info.getRecord_ID());
        }
        //	Init
        if (!dynInit())
            return;
        jbInit();
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
}
Also used : ProcessInfo(org.compiere.process.ProcessInfo)

Example 54 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class WProcess method createProcessPage.

//	createParameterPage
//Modified by Rob klein 4/29/07	
/**************************************************************************
	 * 	Create Parocess Page
	 * 	@param request request
	 *	@param AD_Process_ID Process
	 *	@return Page
	 */
public void createProcessPage(HttpServletRequest request, HttpServletResponse response, int AD_Process_ID, int AD_Window_ID) {
    MobileSessionCtx wsc = MobileSessionCtx.get(request);
    MProcess process = MProcess.get(wsc.ctx, AD_Process_ID);
    log.info("PI table id " + process.get_Table_ID());
    log.info("PI table name id " + process.get_TableName());
    log.info("PI table client id " + process.getAD_Client_ID());
    log.info("PI table process id " + process.getAD_Process_ID());
    log.info("PI  process class name " + process.getClassname());
    //	need to check if Role can access
    MobileDoc doc = null;
    if (process == null) {
        doc = MobileDoc.createWindow("Process Not Found");
    } else {
        doc = MobileDoc.createWindow(process.getName());
        fieldset center = new fieldset();
        doc.getBody().addElement(center);
        if (process.getDescription() != null)
            center.addElement(new p(new i(process.getDescription())));
        if (process.getHelp() != null)
            center.addElement(new p(process.getHelp(), AlignType.LEFT));
        //	Create Process Instance
        MPInstance pInstance = fillParameter(request, process);
        //		
        int AD_Table_ID = MobileUtil.getParameterAsInt(request, "AD_Table_ID");
        int AD_Record_ID = MobileUtil.getParameterAsInt(request, "AD_Record_ID");
        ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID(), AD_Table_ID, AD_Record_ID);
        pi.setAD_User_ID(Env.getAD_User_ID(wsc.ctx));
        pi.setAD_Client_ID(Env.getAD_Client_ID(wsc.ctx));
        pi.setClassName(process.getClassname());
        log.info("PI client id " + pi.getAD_Client_ID());
        pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
        //	Info
        p p = new p();
        p.addElement(Msg.translate(wsc.ctx, "AD_PInstance_ID") + ": " + pInstance.getAD_PInstance_ID());
        center.addElement(p);
        //	Start
        boolean processOK = false;
        if (process.isWorkflow()) {
            Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
            try {
                WProcessCtl.process(this, AD_Window_ID, pi, trx, request);
                //processOK = process.processIt(pi, trx);			
                trx.commit();
                trx.close();
            } catch (Throwable t) {
                trx.rollback();
                trx.close();
            }
            if (pi.isError()) {
                center.addElement(new p("Error:" + pi.getSummary(), AlignType.LEFT).setClass("Cerror"));
                processOK = false;
            } else {
                center.addElement(new p("OK: Workflow Started", AlignType.LEFT));
                processOK = true;
            }
            center.addElement(new p().addElement(pi.getSummary()));
            center.addElement(pi.getLogInfo(true));
        }
        String jasper = process.getJasperReport();
        if (process.isJavaProcess()) {
            if (jasper != null) {
                pi.setPrintPreview(false);
                pi.setIsBatch(true);
            }
            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()) {
                center.addElement(new p("Error:" + pi.getSummary(), AlignType.LEFT).setClass("Cerror"));
                processOK = false;
            } else {
                if (jasper != null) {
                    String error = MobileUtil.streamFile(response, pi.getPDFReport());
                    //String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
                    if (error == null)
                        return;
                    doc = MobileDoc.create(error);
                    wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
                } else {
                    center.addElement(new p().addElement(pi.getSummary()));
                    center.addElement(pi.getLogInfo(true));
                }
            }
        }
        //	Report
        if (process.isReport()) //if (processOK && process.isReport())
        {
            if (jasper == null) {
                log.info(response.toString());
                ReportEngine re = ReportEngine.get(wsc.ctx, pi);
                if (re == null) {
                    center.addElement(new p("Could not start ReportEngine", AlignType.LEFT).setClass("Cerror"));
                } else {
                    try {
                        File file = File.createTempFile("WProcess", ".pdf");
                        boolean ok = re.createPDF(file);
                        if (ok) {
                            String error = MobileUtil.streamFile(response, file);
                            //String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
                            if (error == null)
                                return;
                            doc = MobileDoc.create(error);
                            //Modified by Rob Klein 6/1/07
                            /**
							String url = "WProcess?AD_PInstance_ID=" 
								+ pInstance.getAD_PInstance_ID()
								+ "&File=" 
								+ URLEncoder.encode(file.getAbsolutePath(), WebEnv.ENCODING);
							a link = new a (url, null, a.TARGET_BLANK, process.getName());
							center
								.addElement(new p()
									.addElement("Report created: ")
									.addElement(link));
							//	Marker that Process is OK
							 * */
                            wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
                        } else
                            center.addElement(new p("Could not create Report", AlignType.LEFT).setClass("Cerror"));
                    } catch (Exception e) {
                        center.addElement(new p("Could not create Report:", AlignType.LEFT).setClass("Cerror"));
                        center.addElement(e.toString());
                    }
                }
            }
        }
    }
    try {
        MobileUtil.createResponse(request, response, this, null, doc, false);
    } catch (IOException e) {
        log.info(e.toString());
    }
}
Also used : MProcess(org.compiere.model.MProcess) org.apache.ecs.xhtml.fieldset(org.apache.ecs.xhtml.fieldset) org.apache.ecs.xhtml.i(org.apache.ecs.xhtml.i) org.apache.ecs.xhtml.li(org.apache.ecs.xhtml.li) ProcessInfo(org.compiere.process.ProcessInfo) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException) org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) Timestamp(java.sql.Timestamp) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) Trx(org.compiere.util.Trx) File(java.io.File)

Example 55 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class Scheduler method runProcess.

//	doWork
/**
	 * 	Run Process or Report
	 *	@param process process
	 *	@return summary
	 *	@throws Exception
	 */
private String runProcess(MProcess process) throws Exception {
    log.info(process.toString());
    boolean isReport = (process.isReport() || process.getAD_ReportView_ID() > 0);
    //	Process (see also MWFActivity.performWork
    int AD_Table_ID = m_model.getAD_Table_ID();
    int Record_ID = m_model.getRecord_ID();
    //
    MPInstance pInstance = new MPInstance(process, Record_ID);
    fillParameter(pInstance);
    //
    ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID(), AD_Table_ID, Record_ID);
    pi.setAD_User_ID(getAD_User_ID());
    pi.setAD_Client_ID(m_model.getAD_Client_ID());
    pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
    MUser from = new MUser(getCtx(), pi.getAD_User_ID(), null);
    if (// note, this call close the transaction, don't use m_trx below
    !process.processIt(pi, m_trx)) {
        // notify supervisor if error
        int supervisor = m_model.getSupervisor_ID();
        if (supervisor > 0) {
            MUser user = new MUser(getCtx(), supervisor, null);
            boolean email = user.isNotificationEMail();
            boolean notice = user.isNotificationNote();
            if (email || notice)
                ProcessInfoUtil.setLogFromDB(pi);
            if (email) {
                MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID());
                client.sendEMail(from, user, process.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
            }
            if (notice) {
                // HARDCODED ProcessRunError
                int AD_Message_ID = 442;
                MNote note = new MNote(getCtx(), AD_Message_ID, supervisor, null);
                note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
                note.setTextMsg(pi.getSummary());
                //note.setDescription();
                note.setRecord(MPInstance.Table_ID, pi.getAD_PInstance_ID());
                note.saveEx();
            }
        }
    } else {
        // notify recipients on success
        Integer[] userIDs = m_model.getRecipientAD_User_IDs();
        if (userIDs.length > 0) {
            ProcessInfoUtil.setLogFromDB(pi);
            for (int i = 0; i < userIDs.length; i++) {
                MUser user = new MUser(getCtx(), userIDs[i].intValue(), null);
                boolean email = user.isNotificationEMail();
                boolean notice = user.isNotificationNote();
                File report = null;
                if (isReport) {
                    //	Report
                    ReportEngine re = ReportEngine.get(m_schedulerctx, pi);
                    if (re == null)
                        return "Cannot create Report AD_Process_ID=" + process.getAD_Process_ID() + " - " + process.getName();
                    report = re.getPDF();
                }
                if (notice) {
                    // ProcessOK
                    int AD_Message_ID = 441;
                    if (isReport)
                        //	HARDCODED SchedulerResult
                        AD_Message_ID = 884;
                    MNote note = new MNote(getCtx(), AD_Message_ID, userIDs[i].intValue(), null);
                    note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
                    if (isReport) {
                        note.setTextMsg(m_model.getName());
                        note.setDescription(m_model.getDescription());
                        note.setRecord(AD_Table_ID, Record_ID);
                    } else {
                        note.setTextMsg(pi.getSummary());
                        // note.setDescription();
                        note.setRecord(MPInstance.Table_ID, pi.getAD_PInstance_ID());
                    }
                    if (note.save()) {
                        if (isReport) {
                            //	Attachment
                            MAttachment attachment = new MAttachment(getCtx(), MNote.Table_ID, note.getAD_Note_ID(), null);
                            attachment.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
                            attachment.addEntry(report);
                            attachment.setTextMsg(m_model.getName());
                            attachment.saveEx();
                        }
                    }
                }
                if (email) {
                    MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID());
                    if (isReport) {
                        client.sendEMail(from, user, m_model.getName(), m_model.getDescription(), report);
                    } else {
                        client.sendEMail(from, user, process.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
                    }
                }
            }
        }
    }
    return pi.getSummary();
}
Also used : MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) MAttachment(org.compiere.model.MAttachment) ProcessInfo(org.compiere.process.ProcessInfo) MUser(org.compiere.model.MUser) MNote(org.compiere.model.MNote) File(java.io.File) MClient(org.compiere.model.MClient)

Aggregations

ProcessInfo (org.compiere.process.ProcessInfo)65 MPInstance (org.compiere.model.MPInstance)21 Trx (org.compiere.util.Trx)17 AdempiereException (org.adempiere.exceptions.AdempiereException)14 MPInstancePara (org.compiere.model.MPInstancePara)12 ReportEngine (org.compiere.print.ReportEngine)11 File (java.io.File)10 MProcess (org.compiere.model.MProcess)9 ProcessCtl (org.compiere.apps.ProcessCtl)8 SQLException (java.sql.SQLException)6 Timestamp (java.sql.Timestamp)6 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)4 MBrowse (org.adempiere.model.MBrowse)4 PrintInfo (org.compiere.model.PrintInfo)4 ProcessInfoParameter (org.compiere.process.ProcessInfoParameter)4 Properties (java.util.Properties)3 MMovement (org.compiere.model.MMovement)3 PO (org.compiere.model.PO)3