/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.wf;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.model.MRole;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.Query;
import org.compiere.model.X_AD_WF_Process;
import org.compiere.process.DocAction;
import org.compiere.process.ProcessInfo;
import org.compiere.process.StateEngine;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
import org.compiere.util.Util;
/**
* Extended Workflow Process model for AD_WF_Process
*
* @author Jorg Janke
* @author Silvano Trinchero, www.freepath.it
*
IDEMPIERE-3209 changed fucntions to public to improve integration support
* @version $Id: MWFProcess.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
*/
public class MWFProcess extends X_AD_WF_Process
{
/**
* generated serial id
*/
private static final long serialVersionUID = 5981488658756275526L;
/**
* UUID based Constructor
* @param ctx Context
* @param AD_WF_Process_UU UUID key
* @param trxName Transaction
*/
public MWFProcess(Properties ctx, String AD_WF_Process_UU, String trxName) {
super(ctx, AD_WF_Process_UU, trxName);
if (Util.isEmpty(AD_WF_Process_UU))
throw new IllegalArgumentException ("Cannot create new WF Process directly");
m_state = new StateEngine (getWFState());
}
/**
* Standard Constructor
* @param ctx context
* @param AD_WF_Process_ID process
* @param trxName transaction
*/
public MWFProcess (Properties ctx, int AD_WF_Process_ID, String trxName)
{
super (ctx, AD_WF_Process_ID, trxName);
if (AD_WF_Process_ID == 0)
throw new IllegalArgumentException ("Cannot create new WF Process directly");
m_state = new StateEngine (getWFState());
} // MWFProcess
/**
* Load Constructor
* @param ctx context
* @param rs result set
* @param trxName transaction
*/
public MWFProcess (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
m_state = new StateEngine (getWFState());
} // MWFProcess
/**
* New Constructor
* @param wf workflow
* @param pi Process Info (Record_ID)
* @deprecated
* @throws Exception
*/
public MWFProcess (MWorkflow wf, ProcessInfo pi) throws Exception
{
this(wf, pi, wf.get_TrxName());
}
/**
* New Constructor
* @param wf workflow
* @param pi Process Info (Record_ID)
* @param trxName
* @throws Exception
*/
public MWFProcess (MWorkflow wf, ProcessInfo pi, String trxName) throws Exception
{
super (wf.getCtx(), 0, trxName);
if (!TimeUtil.isValid(wf.getValidFrom(), wf.getValidTo()))
throw new IllegalStateException("Workflow not valid");
m_wf = wf;
m_pi = pi;
setAD_Workflow_ID (wf.getAD_Workflow_ID());
setPriority(wf.getPriority());
super.setWFState (WFSTATE_NotStarted);
// Document
setAD_Table_ID(wf.getAD_Table_ID());
setRecord_ID(pi.getRecord_ID());
if (pi.getPO() != null)
m_po = pi.getPO();
if (getPO() == null)
{
setTextMsg("No PO with ID=" + pi.getRecord_ID());
addTextMsg(new Exception(""));
super.setWFState (WFSTATE_Terminated);
}
else
setTextMsg(getPO());
// Responsible/User
if (wf.getAD_WF_Responsible_ID() == 0)
setAD_WF_Responsible_ID();
else
setAD_WF_Responsible_ID(wf.getAD_WF_Responsible_ID());
setUser_ID(pi.getAD_User_ID()); // user starting
//
m_state = new StateEngine (getWFState());
setProcessed (false);
// Lock Entity
getPO();
setAD_Org_ID(m_po.getAD_Org_ID());//Add by Hideaki Hagiwara
} // MWFProcess
/** State Machine */
private StateEngine m_state = null;
/** Activities */
private MWFActivity[] m_activities = null;
/** Workflow */
private MWorkflow m_wf = null;
/** Process Info */
private ProcessInfo m_pi = null;
/** Persistent Object */
private PO m_po = null;
/** Message from Activity */
private String m_processMsg = null;
/**
* Get active Activities of Process
* @param requery true to reload from DB
* @param onlyActive only active activities
* @return array of activities
*/
public MWFActivity[] getActivities (boolean requery, boolean onlyActive)
{
return getActivities(requery, onlyActive, get_TrxName());
}
/**
* Get active Activities of Process
* @param requery true to reload from DB
* @param onlyActive only active activities
* @return array of activities
*/
public MWFActivity[] getActivities (boolean requery, boolean onlyActive, String trxName)
{
if (!requery && m_activities != null)
return m_activities;
//
ArrayList