Search in sources :

Example 51 with Trx

use of org.compiere.util.Trx in project adempiere by adempiere.

the class ServerReportCtl method runJasperProcess.

//	StartDocumentPrint
/**
	 * Runs a Jasper process that prints the record
	 *
	 * @param recordId
	 * @param reportEngine
	 * @param isDirectPrint
	 * @param printerName
	 * @param processInfo
     * @return
     */
public static boolean runJasperProcess(int recordId, ReportEngine reportEngine, boolean isDirectPrint, String printerName, ProcessInfo processInfo) {
    Trx trx;
    if (processInfo != null)
        trx = Trx.get(processInfo.getTransactionName(), false);
    else
        trx = null;
    MPrintFormat format = reportEngine.getPrintFormat();
    ProcessInfo jasperProcessInfo = new ProcessInfo("", format.getJasperProcess_ID());
    jasperProcessInfo.setPrintPreview(!isDirectPrint);
    MQuery query = reportEngine.getQuery();
    if (query != null)
        recordId = (Integer) query.getCode(0);
    jasperProcessInfo.setRecord_ID(recordId);
    Vector<ProcessInfoParameter> jasperPrintParams = new Vector<ProcessInfoParameter>();
    ProcessInfoParameter pip;
    if (printerName != null && printerName.trim().length() > 0) {
        // Override printer name
        pip = new ProcessInfoParameter(PARAM_PRINTER_NAME, printerName, null, null, null);
        jasperPrintParams.add(pip);
    }
    pip = new ProcessInfoParameter(PARAM_PRINT_FORMAT, format, null, null, null);
    jasperPrintParams.add(pip);
    pip = new ProcessInfoParameter(PARAM_PRINT_INFO, reportEngine.getPrintInfo(), null, null, null);
    jasperPrintParams.add(pip);
    jasperProcessInfo.setParameter(jasperPrintParams.toArray(new ProcessInfoParameter[] {}));
    // Parent set to null for synchronous processing, see bugtracker 3010932  
    ServerProcessCtl.process(// Parent set to null for synchronous processing, see bugtracker 3010932  
    null, jasperProcessInfo, trx);
    if (processInfo != null)
        processInfo.setPDFReport(jasperProcessInfo.getPDFReport());
    boolean result = true;
    return (result);
}
Also used : ProcessInfoParameter(org.compiere.process.ProcessInfoParameter) MQuery(org.compiere.model.MQuery) Trx(org.compiere.util.Trx) ProcessInfo(org.compiere.process.ProcessInfo) Vector(java.util.Vector)

Example 52 with Trx

use of org.compiere.util.Trx in project adempiere by adempiere.

the class FinReportJasper method doIt.

/**************************************************************************
	 *  Perform process.
	 *  @return Message to be translated
	 *  @throws Exception
	 */
protected String doIt() throws Exception {
    // Call the normal FinReport to fill the T_Report table
    String finReportMsg = super.doIt();
    // Now invoke the associated jasper report (must report on the T_Report table)
    ArrayList<ProcessInfoParameter> list = new ArrayList<ProcessInfoParameter>();
    // Copy the list of parameters from the financial report
    ProcessInfoParameter[] oldpara = getParameter();
    for (int i = 0; i < oldpara.length; i++) list.add(oldpara[i]);
    // and add the T_Report_AD_PInstance_ID parameter
    list.add(new ProcessInfoParameter("T_Report_AD_PInstance_ID", new Integer(getAD_PInstance_ID()), null, null, null));
    ProcessInfoParameter[] pars = new ProcessInfoParameter[list.size()];
    list.toArray(pars);
    //	Load Report Definition
    m_report = new MReport(getCtx(), getRecord_ID(), get_TrxName());
    MProcess proc = new MProcess(getCtx(), m_report.getJasperProcess_ID(), get_TrxName());
    MPInstance instance = new MPInstance(proc, getRecord_ID());
    instance.saveEx();
    ProcessInfo poInfo = new ProcessInfo(proc.getName(), proc.getAD_Process_ID());
    poInfo.setParameter(pars);
    poInfo.setRecord_ID(getRecord_ID());
    poInfo.setAD_Process_ID(proc.getAD_Process_ID());
    poInfo.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    // need to commit in order to allow jasper to view the data
    Trx trx = Trx.get(get_TrxName(), true);
    trx.commit();
    // CarlosRuiz - globalqss - allow procedure preprocess
    if (proc.getProcedureName() != null && proc.getProcedureName().length() > 0) {
        //  execute on this thread/connection
        String sql = "{call " + proc.getProcedureName() + "(?)}";
        try {
            //	ro??
            CallableStatement cstmt = DB.prepareCall(sql);
            cstmt.setInt(1, getAD_PInstance_ID());
            cstmt.executeUpdate();
            cstmt.close();
        } catch (Exception e) {
            log.log(Level.SEVERE, sql, e);
            poInfo.setSummary(Msg.getMsg(Env.getCtx(), "ProcessRunError") + " " + e.getLocalizedMessage());
        }
    }
    // TODO - allow java class preprocess if the classname <> ProcessUtil.JASPER_STARTER_CLASS
    ProcessUtil.startJavaProcess(getCtx(), poInfo, trx);
    return finReportMsg;
}
Also used : MProcess(org.compiere.model.MProcess) ArrayList(java.util.ArrayList) ProcessInfo(org.compiere.process.ProcessInfo) ProcessInfoParameter(org.compiere.process.ProcessInfoParameter) MPInstance(org.compiere.model.MPInstance) CallableStatement(java.sql.CallableStatement) Trx(org.compiere.util.Trx)

Example 53 with Trx

use of org.compiere.util.Trx in project adempiere by adempiere.

the class ProcessBuilder method processCtl.

/**
     * Create instancel for process control
     * @param className
     * @param parent
     * @param windowNo
     * @param processInfo
     * @param trx
     * @return
     * @throws RuntimeException
     */
private Runnable processCtl(String className, ASyncProcess parent, int windowNo, ProcessInfo processInfo, Trx trx) throws RuntimeException {
    Class<?> clazz;
    Runnable result = null;
    try {
        clazz = Class.forName(className);
        Constructor<?> constructor = null;
        if (windowNo == 0) {
            constructor = clazz.getDeclaredConstructor(ASyncProcess.class, ProcessInfo.class, Trx.class);
            result = (Runnable) constructor.newInstance(parent, processInfo, trx);
        } else {
            constructor = clazz.getDeclaredConstructor(ASyncProcess.class, Integer.class, ProcessInfo.class, Trx.class);
            result = (Runnable) constructor.newInstance(parent, windowNo, processInfo, trx);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return result;
}
Also used : TrxRunnable(org.compiere.util.TrxRunnable) ASyncProcess(org.compiere.util.ASyncProcess) ProcessInfo(org.compiere.process.ProcessInfo) Trx(org.compiere.util.Trx) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 54 with Trx

use of org.compiere.util.Trx 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 Trx

use of org.compiere.util.Trx in project adempiere by adempiere.

the class VOrderDistributionReceipt method generateMovements.

//	saveSelection
/**************************************************************************
	 *	Generate Shipments
	 */
private void generateMovements() {
    log.info("DD_Order_ID=" + m_DD_Order_ID);
    log.info("MovementDate" + m_MovementDate);
    String trxName = Trx.createTrxName("IOG");
    //trx needs to be committed too
    Trx trx = Trx.get(trxName, true);
    //  prevents from being called twice
    m_selectionActive = false;
    statusBar.setStatusLine(Msg.translate(Env.getCtx(), "M_Movement_ID"));
    statusBar.setStatusDB(String.valueOf(selection.size()));
    if (selection.size() <= 0)
        return;
    Properties m_ctx = Env.getCtx();
    Timestamp MovementDate = (Timestamp) m_MovementDate;
    MDDOrder order = new MDDOrder(m_ctx, Integer.parseInt(m_DD_Order_ID.toString()), trxName);
    MMovement movement = new MMovement(m_ctx, 0, trxName);
    movement.setDD_Order_ID(order.getDD_Order_ID());
    movement.setAD_User_ID(order.getAD_User_ID());
    movement.setPOReference(order.getPOReference());
    movement.setReversal_ID(0);
    movement.setM_Shipper_ID(order.getM_Shipper_ID());
    movement.setDescription(order.getDescription());
    movement.setC_BPartner_ID(order.getC_BPartner_ID());
    movement.setC_BPartner_Location_ID(order.getC_BPartner_Location_ID());
    movement.setAD_Org_ID(order.getAD_Org_ID());
    movement.setAD_OrgTrx_ID(order.getAD_OrgTrx_ID());
    movement.setAD_User_ID(order.getAD_User_ID());
    movement.setC_Activity_ID(order.getC_Activity_ID());
    movement.setC_Campaign_ID(order.getC_Campaign_ID());
    movement.setC_Project_ID(order.getC_Project_ID());
    movement.setMovementDate(MovementDate);
    movement.setDeliveryRule(order.getDeliveryRule());
    movement.setDeliveryViaRule(order.getDeliveryViaRule());
    movement.setDocAction(MMovement.ACTION_Prepare);
    movement.setDocStatus(MMovement.DOCSTATUS_Drafted);
    //Look the document type for the organization
    int docTypeDO_ID = getDocType(MDocType.DOCBASETYPE_MaterialMovement, order.getAD_Org_ID());
    if (docTypeDO_ID > 0)
        movement.setC_DocType_ID(docTypeDO_ID);
    movement.saveEx();
    for (int i = 0; i < selection.size(); i++) {
        int DD_OrderLine_ID = selection.get(i);
        MDDOrderLine oline = new MDDOrderLine(m_ctx, DD_OrderLine_ID, trxName);
        MMovementLine line = new MMovementLine(movement);
        line.setM_Product_ID(oline.getM_Product_ID());
        BigDecimal QtyDeliver = (BigDecimal) miniTable.getValueAt(i, 1);
        if (QtyDeliver == null | QtyDeliver.compareTo(oline.getQtyInTransit()) > 0)
            throw new AdempiereException("Error in Qty");
        line.setOrderLine(oline, QtyDeliver, true);
        line.saveEx();
    }
    movement.setDocAction(MMovement.DOCACTION_Close);
    movement.setDocStatus(movement.completeIt());
    movement.saveEx();
    trx.commit();
    generateMovements_complete(movement);
//
}
Also used : MDDOrderLine(org.eevolution.model.MDDOrderLine) AdempiereException(org.adempiere.exceptions.AdempiereException) Trx(org.compiere.util.Trx) MDDOrder(org.eevolution.model.MDDOrder) Properties(java.util.Properties) MMovementLine(org.compiere.model.MMovementLine) Timestamp(java.sql.Timestamp) MMovement(org.compiere.model.MMovement) BigDecimal(java.math.BigDecimal)

Aggregations

Trx (org.compiere.util.Trx)60 SQLException (java.sql.SQLException)20 ProcessInfo (org.compiere.process.ProcessInfo)16 AdempiereException (org.adempiere.exceptions.AdempiereException)12 MPInstance (org.compiere.model.MPInstance)11 DBException (org.adempiere.exceptions.DBException)10 Timestamp (java.sql.Timestamp)9 File (java.io.File)8 Properties (java.util.Properties)8 Connection (java.sql.Connection)7 MPInstancePara (org.compiere.model.MPInstancePara)7 BigDecimal (java.math.BigDecimal)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 IOException (java.io.IOException)5 MTable (org.compiere.model.MTable)5 PO (org.compiere.model.PO)5 ServletException (javax.servlet.ServletException)4 CConnection (org.compiere.db.CConnection)4 ReportEngine (org.compiere.print.ReportEngine)4