Search in sources :

Example 36 with ProcessInfo

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

the class MSetup method importChart.

public boolean importChart(File chart) {
    // import chart of accounts automatically
    ImpFormat importer = ImpFormat.load("Accounting - Accounts");
    importer.loadFile(m_ctx, chart, m_trx.getTrxName(), m_client.getAD_Client_ID(), 0, true);
    //	Process
    // Import_Account
    MProcess process = MProcess.get(m_ctx, 197);
    MPInstance pInstance = new MPInstance(process, 0);
    pInstance.setAD_Client_ID(m_client.getAD_Client_ID());
    pInstance.setAD_Org_ID(0);
    for (MPInstancePara para : pInstance.getParameters()) {
        String name = para.getParameterName();
        if ("AD_Client_ID".equals(name))
            para.setP_Number(m_client.getAD_Client_ID());
        else if ("C_Element_ID".equals(name))
            para.setP_Number(C_Element_ID);
        para.saveEx();
    }
    //
    ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID(), 0, 0);
    pi.setAD_User_ID(getAD_User_ID());
    pi.setAD_Client_ID(m_client.getAD_Client_ID());
    pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
    if (!process.processItWithoutTrxClose(pi, m_trx))
        return false;
    boolean success = m_trx.commit();
    m_trx.close();
    return success;
}
Also used : ImpFormat(org.compiere.impexp.ImpFormat) ProcessInfo(org.compiere.process.ProcessInfo)

Example 37 with ProcessInfo

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

the class MWFActivity method performWork.

//	run
/**
	 * 	Perform Work.
	 * 	Set Text Msg.
	 * 	@param trx transaction
	 *	@return true if completed, false otherwise
	 *	@throws Exception if error
	 */
private boolean performWork(Trx trx) throws Exception {
    log.info(m_node + " [" + trx.getTrxName() + "]");
    m_docStatus = null;
    if (//	overwrite priority if defined
    m_node.getPriority() != 0)
        setPriority(m_node.getPriority());
    String action = m_node.getAction();
    /******	Sleep (Start/End)			******/
    if (MWFNode.ACTION_WaitSleep.equals(action)) {
        log.fine("Sleep:WaitTime=" + m_node.getWaitTime());
        if (m_node.getWaitingTime() == 0)
            //	done
            return true;
        Calendar cal = Calendar.getInstance();
        cal.add(m_node.getDurationCalendarField(), m_node.getWaitTime());
        setEndWaitTime(new Timestamp(cal.getTimeInMillis()));
        //	not done
        return false;
    } else /******	Document Action				******/
    if (MWFNode.ACTION_DocumentAction.equals(action)) {
        log.fine("DocumentAction=" + m_node.getDocAction());
        getPO(trx);
        if (m_po == null)
            throw new Exception("Persistent Object not found - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
        boolean success = false;
        String processMsg = null;
        DocAction doc = null;
        if (m_po instanceof DocAction) {
            doc = (DocAction) m_po;
            //
            try {
                //	** Do the work
                success = doc.processIt(m_node.getDocAction());
                setTextMsg(doc.getSummary());
                processMsg = doc.getProcessMsg();
                // the rest of methods return boolean, so doc status must not be taken into account when not successful
                if (DocAction.ACTION_Prepare.equals(m_node.getDocAction()) || DocAction.ACTION_Complete.equals(m_node.getDocAction()) || success)
                    m_docStatus = doc.getDocStatus();
            } catch (Exception e) {
                if (m_process != null)
                    m_process.setProcessMsg(e.getLocalizedMessage());
                throw e;
            }
            if (m_process != null)
                m_process.setProcessMsg(processMsg);
        } else
            throw new IllegalStateException("Persistent Object not DocAction - " + m_po.getClass().getName() + " - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
        //
        if (!m_po.save()) {
            success = false;
            processMsg = "SaveError";
        }
        if (!success) {
            if (processMsg == null || processMsg.length() == 0) {
                processMsg = "PerformWork Error - " + m_node.toStringX();
                if (//	problem: status will be rolled back
                doc != null)
                    processMsg += " - DocStatus=" + doc.getDocStatus();
            }
            throw new Exception(processMsg);
        }
        return success;
    } else /******	Report						******/
    if (MWFNode.ACTION_AppsReport.equals(action)) {
        log.fine("Report:AD_Process_ID=" + m_node.getAD_Process_ID());
        //	Process
        MProcess process = MProcess.get(getCtx(), m_node.getAD_Process_ID());
        process.set_TrxName(trx != null ? trx.getTrxName() : null);
        if (!process.isReport() || process.getAD_ReportView_ID() == 0)
            throw new IllegalStateException("Not a Report AD_Process_ID=" + m_node.getAD_Process_ID());
        //
        ProcessInfo pi = new ProcessInfo(m_node.getName(true), m_node.getAD_Process_ID(), getAD_Table_ID(), getRecord_ID());
        pi.setAD_User_ID(getAD_User_ID());
        pi.setAD_Client_ID(getAD_Client_ID());
        MPInstance pInstance = new MPInstance(process, getRecord_ID());
        pInstance.set_TrxName(trx != null ? trx.getTrxName() : null);
        fillParameter(pInstance, trx);
        pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
        //	Report
        ReportEngine re = ReportEngine.get(getCtx(), pi);
        if (re == null)
            throw new IllegalStateException("Cannot create Report AD_Process_ID=" + m_node.getAD_Process_ID());
        File report = re.getPDF();
        //	Notice
        //	HARDCODED WorkflowResult
        int AD_Message_ID = 753;
        MNote note = new MNote(getCtx(), AD_Message_ID, getAD_User_ID(), trx.getTrxName());
        note.setTextMsg(m_node.getName(true));
        note.setDescription(m_node.getDescription(true));
        note.setRecord(getAD_Table_ID(), getRecord_ID());
        note.saveEx();
        //	Attachment
        MAttachment attachment = new MAttachment(getCtx(), MNote.Table_ID, note.getAD_Note_ID(), get_TrxName());
        attachment.addEntry(report);
        attachment.setTextMsg(m_node.getName(true));
        attachment.saveEx();
        return true;
    } else /******	Process						******/
    if (MWFNode.ACTION_AppsProcess.equals(action)) {
        log.fine("Process:AD_Process_ID=" + m_node.getAD_Process_ID());
        //	Process
        MProcess process = MProcess.get(getCtx(), m_node.getAD_Process_ID());
        MPInstance pInstance = new MPInstance(process, getRecord_ID());
        fillParameter(pInstance, trx);
        //
        ProcessInfo pi = new ProcessInfo(m_node.getName(true), m_node.getAD_Process_ID(), getAD_Table_ID(), getRecord_ID());
        pi.setAD_User_ID(getAD_User_ID());
        pi.setAD_Client_ID(getAD_Client_ID());
        pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
        return process.processItWithoutTrxClose(pi, trx);
    } else /******	EMail						******/
    if (MWFNode.ACTION_EMail.equals(action)) {
        log.fine("EMail:EMailRecipient=" + m_node.getEMailRecipient());
        getPO(trx);
        if (m_po == null)
            throw new Exception("Persistent Object not found - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
        if (m_po instanceof DocAction) {
            m_emails = new ArrayList<String>();
            sendEMail();
            setTextMsg(m_emails.toString());
        } else {
            MClient client = MClient.get(getCtx(), getAD_Client_ID());
            MMailText mailtext = new MMailText(getCtx(), getNode().getR_MailText_ID(), null);
            String subject = getNode().getDescription() + ": " + mailtext.getMailHeader();
            String message = mailtext.getMailText(true) + "\n-----\n" + getNodeHelp();
            String to = getNode().getEMail();
            client.sendEMail(to, subject, message, null);
        }
        //	done
        return true;
    } else /******	Set Variable				******/
    if (MWFNode.ACTION_SetVariable.equals(action)) {
        String value = m_node.getAttributeValue();
        log.fine("SetVariable:AD_Column_ID=" + m_node.getAD_Column_ID() + " to " + value);
        MColumn column = m_node.getColumn();
        int dt = column.getAD_Reference_ID();
        return setVariable(value, dt, null, trx);
    } else /******	TODO Start WF Instance		******/
    if (MWFNode.ACTION_SubWorkflow.equals(action)) {
        log.warning("Workflow:AD_Workflow_ID=" + m_node.getAD_Workflow_ID());
        log.warning("Start WF Instance is not implemented yet");
    } else /******	User Choice					******/
    if (MWFNode.ACTION_UserChoice.equals(action)) {
        log.fine("UserChoice:AD_Column_ID=" + m_node.getAD_Column_ID());
        //	Approval
        if (m_node.isUserApproval() && getPO(trx) instanceof DocAction) {
            DocAction doc = (DocAction) m_po;
            boolean autoApproval = false;
            //	Approval Hierarchy
            if (isInvoker()) {
                //	Set Approver
                int startAD_User_ID = Env.getAD_User_ID(getCtx());
                if (startAD_User_ID == 0)
                    startAD_User_ID = doc.getDoc_User_ID();
                int nextAD_User_ID = getApprovalUser(startAD_User_ID, doc.getC_Currency_ID(), doc.getApprovalAmt(), doc.getAD_Org_ID(), //	own doc
                startAD_User_ID == doc.getDoc_User_ID());
                //	same user = approved
                autoApproval = startAD_User_ID == nextAD_User_ID;
                if (!autoApproval)
                    setAD_User_ID(nextAD_User_ID);
            } else //	fixed Approver
            {
                MWFResponsible resp = getResponsible();
                // [ 1742751 ] Workflow: User Choice is not working
                if (resp.isHuman()) {
                    autoApproval = resp.getAD_User_ID() == Env.getAD_User_ID(getCtx());
                    if (!autoApproval && resp.getAD_User_ID() != 0)
                        setAD_User_ID(resp.getAD_User_ID());
                } else if (resp.isRole()) {
                    MUserRoles[] urs = MUserRoles.getOfRole(getCtx(), resp.getAD_Role_ID());
                    for (int i = 0; i < urs.length; i++) {
                        if (urs[i].getAD_User_ID() == Env.getAD_User_ID(getCtx())) {
                            autoApproval = true;
                            break;
                        }
                    }
                } else if (resp.isOrganization()) {
                    throw new AdempiereException("Support not implemented for " + resp);
                } else {
                    throw new AdempiereException("@NotSupported@ " + resp);
                }
            // end MZ
            }
            if (autoApproval && doc.processIt(DocAction.ACTION_Approve) && doc.save())
                //	done
                return true;
        }
        //	wait for user
        return false;
    } else /******	User Form					******/
    if (MWFNode.ACTION_UserForm.equals(action)) {
        log.fine("Form:AD_Form_ID=" + m_node.getAD_Form_ID());
        return false;
    } else if (MWFNode.ACTION_SmartBrowse.equals(action)) {
        log.fine("Form:AD_Browse_ID=" + m_node.getAD_Browse_ID());
        return false;
    } else /******	User Window					******/
    if (MWFNode.ACTION_UserWindow.equals(action)) {
        log.fine("Window:AD_Window_ID=" + m_node.getAD_Window_ID());
        return false;
    }
    //
    throw new IllegalArgumentException("Invalid Action (Not Implemented) =" + action);
}
Also used : MColumn(org.compiere.model.MColumn) MProcess(org.compiere.model.MProcess) MAttachment(org.compiere.model.MAttachment) DocAction(org.compiere.process.DocAction) MMailText(org.compiere.model.MMailText) Calendar(java.util.Calendar) MUserRoles(org.compiere.model.MUserRoles) ProcessInfo(org.compiere.process.ProcessInfo) Timestamp(java.sql.Timestamp) SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException) Savepoint(java.sql.Savepoint) MClient(org.compiere.model.MClient) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) AdempiereException(org.adempiere.exceptions.AdempiereException) File(java.io.File) MNote(org.compiere.model.MNote)

Example 38 with ProcessInfo

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

the class DocWorkflowManager method process.

/**
	 * 	Process Document Value Workflow
	 *	@param document document
	 *	@param AD_Table_ID table
	 *	@return true if WF started
	 */
public boolean process(PO document, int AD_Table_ID) {
    m_noCalled++;
    MWorkflow[] wfs = MWorkflow.getDocValue(document.getCtx(), document.getAD_Client_ID(), AD_Table_ID, // Bug 1568766 Trx should be kept all along the road	
    document.get_TrxName());
    if (wfs == null || wfs.length == 0)
        return false;
    boolean started = false;
    for (int i = 0; i < wfs.length; i++) {
        MWorkflow wf = wfs[i];
        //	We have a Document Workflow
        String logic = wf.getDocValueLogic();
        if (logic == null || logic.length() == 0) {
            log.severe("Workflow has no Logic - " + wf.getName());
            continue;
        }
        //	Re-check: Document must be same Client as workflow
        if (wf.getAD_Client_ID() != document.getAD_Client_ID())
            continue;
        //	Check Logic
        boolean sql = logic.startsWith("SQL=");
        if (sql && !testStart(wf, document)) {
            log.fine("SQL Logic evaluated to false (" + logic + ")");
            continue;
        }
        if (!sql && !Evaluator.evaluateLogic(document, logic)) {
            log.fine("Logic evaluated to false (" + logic + ")");
            continue;
        }
        //	Start Workflow
        log.fine(logic);
        //	HARDCODED
        int AD_Process_ID = 305;
        ProcessInfo pi = new ProcessInfo(wf.getName(), AD_Process_ID, AD_Table_ID, document.get_ID());
        pi.setAD_User_ID(Env.getAD_User_ID(document.getCtx()));
        pi.setAD_Client_ID(document.getAD_Client_ID());
        //
        if (wf.start(pi, document.get_TrxName()) != null) {
            log.config(wf.getName());
            m_noStarted++;
            started = true;
        }
    }
    return started;
}
Also used : ProcessInfo(org.compiere.process.ProcessInfo)

Example 39 with ProcessInfo

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

the class APanel method cmd_print.

/**
	 *	Print specific Report - or start default Report
	 */
private void cmd_print(boolean printPreview) {
    //	Get process defined for this tab
    int AD_Process_ID = m_curTab.getAD_Process_ID();
    log.info("ID=" + AD_Process_ID);
    //	No report defined
    if (AD_Process_ID == 0) {
        cmd_report();
        return;
    }
    cmd_save(false);
    //
    int table_ID = m_curTab.getAD_Table_ID();
    int record_ID = m_curTab.getRecord_ID();
    ProcessInfo pi = new ProcessInfo(getTitle(), AD_Process_ID, table_ID, record_ID);
    pi.setAD_User_ID(Env.getAD_User_ID(m_ctx));
    pi.setAD_Client_ID(Env.getAD_Client_ID(m_ctx));
    pi.setPrintPreview(printPreview);
    //  calls lockUI, unlockUI
    ProcessCtl.process(this, m_curWindowNo, pi, null);
    statusBar.setStatusLine(pi.getSummary(), pi.isError());
}
Also used : ProcessInfo(org.compiere.process.ProcessInfo) Point(java.awt.Point)

Example 40 with ProcessInfo

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

the class VPaySelect method generatePaySelect.

//  calculateSelection
/**
	 *  Generate PaySelection
	 */
private void generatePaySelect() {
    miniTable.stopEditor(true);
    if (miniTable.getRowCount() == 0)
        return;
    miniTable.setRowSelectionInterval(0, 0);
    calculateSelection();
    if (m_noSelected == 0)
        return;
    String msg = generatePaySelect(miniTable, (ValueNamePair) fieldPaymentRule.getSelectedItem(), fieldPayDate.getTimestamp(), (BankInfo) fieldBankAccount.getSelectedItem());
    if (msg != null && msg.length() > 0) {
        ADialog.error(m_WindowNo, panel, "SaveError", msg);
        return;
    }
    //  Ask to Post it
    if (!ADialog.ask(m_WindowNo, panel, "VPaySelectGenerate?", "(" + m_ps.getDocumentNo() + ")"))
        return;
    //  Prepare Process
    //	C_PaySelection_CreatePayment
    int AD_Proces_ID = 155;
    ProcessInfo pi = new ProcessInfo(m_frame.getTitle(), AD_Proces_ID, X_C_PaySelection.Table_ID, m_ps.getC_PaySelection_ID());
    pi.setAD_User_ID(Env.getAD_User_ID(Env.getCtx()));
    pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx()));
    ProcessPanel pp = new ProcessPanel(m_WindowNo, pi);
    //	Execute Process
    //	BR [ 265 ]
    ProcessCtl.process(this, m_WindowNo, pp, pi, trx);
//	ProcessCtl worker = new ProcessCtl(this, pi, trx);
//	worker.start();     //  complete tasks in unlockUI
}
Also used : ProcessPanel(org.compiere.apps.ProcessPanel) ProcessInfo(org.compiere.process.ProcessInfo)

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