Пример #1
0
 /// <summary>
 ///Parent Constructor
 /// </summary>
 /// <param name="parent">parent</param>
 /// <param name="AD_Role_ID">role id</param>
 public MWorkflowAccess(MWorkflow parent, int AD_Role_ID)
     : base(parent.GetCtx(), 0, parent.Get_TrxName())
 {
     SetClientOrg(parent);
     SetAD_Workflow_ID(parent.GetAD_Workflow_ID());
     SetAD_Role_ID(AD_Role_ID);
 }
Пример #2
0
 /// <summary>
 /// Parent Constructor
 /// </summary>
 /// <param name="wf">workflow (parent)</param>
 /// <param name="Value">value</param>
 /// <param name="Name">name</param>
 public MWFNode(MWorkflow wf, String value, String name)
     : base(wf.GetCtx(), 0, wf.Get_Trx())
 {
     SetClientOrg(wf);
     SetAD_Workflow_ID(wf.GetAD_Workflow_ID());
     SetValue(value);
     SetName(name);
     _durationBaseMS = wf.GetDurationBaseSec() * 1000;
 }
Пример #3
0
        /// <summary>
        /// New Constructor
        /// </summary>
        /// <param name="wf">workflow</param>
        /// <param name="pi">Process Info (Record_ID)</param>
        public MWFProcess(MWorkflow wf, ProcessInfo pi)
            : base(wf.GetCtx(), 0, wf.Get_TrxName())
        {
            if (!Utility.TimeUtil.IsValid(wf.GetValidFrom(), wf.GetValidTo())) // make this class or this function
            {
                //throw new IllegalStateException("Workflow not valid");
                throw new Exception("Workflow not valid");
            }
            _wf = wf;
            _pi = pi;
            SetAD_Client_ID(wf.GetAD_Client_ID());
            SetAD_Workflow_ID(wf.GetAD_Workflow_ID());
            SetPriority(wf.GetPriority());
            base.SetWFState(WFSTATE_NotStarted);

            // vinay bhatt for window id
            SetAD_Window_ID(pi.GetAD_Window_ID());
            //

            //	Document
            SetAD_Table_ID(wf.GetAD_Table_ID());
            SetRecord_ID(pi.GetRecord_ID());
            if (GetPO() == null)
            {
                SetTextMsg("No PO with ID=" + pi.GetRecord_ID());
                base.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((int)pi.GetAD_User_ID());                //	user starting
            //
            _state = new StateEngine(GetWFState());
            _state.SetCtx(GetCtx());
            SetProcessed(false);
            //	Lock Entity
            GetPO();
            if (_po != null)
            {
                // Set transaction organization on workflow process
                SetAD_Org_ID(_po.GetAD_Org_ID());
                _po.Lock();
            }
        }
Пример #4
0
 /// <summary>
 /// Get Workflow
 /// </summary>
 /// <returns>workflow</returns>
 private MWorkflow GetWorkflow()
 {
     if (_wf == null)
     {
         _wf = MWorkflow.Get(GetCtx(), GetAD_Workflow_ID());
     }
     if (_wf.Get_ID() == 0)
     {
         //throw new IllegalStateException("Not found - AD_Workflow_ID=" + getAD_Workflow_ID());
         throw new Exception("Not found - AD_Workflow_ID=" + GetAD_Workflow_ID());
     }
     return(_wf);
 }
Пример #5
0
        /// <summary>
        /// Get Doc Value Workflow
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="AD_Client_ID">client</param>
        /// <param name="AD_Table_ID">table</param>
        /// <returns>document value workflow array or null</returns>
        public static MWorkflow[] GetDocValue(Ctx ctx, int AD_Client_ID, int AD_Table_ID)
        {
            String key = "C" + AD_Client_ID + "T" + AD_Table_ID;

            //Reload
            if (_cacheDocValue.IsReset())
            {
                String sql = "SELECT * FROM AD_Workflow "
                             + "WHERE WorkflowType='V' AND IsActive='Y' AND IsValid='Y' "
                             + "ORDER BY AD_Client_ID, AD_Table_ID";
                List <MWorkflow> list   = new List <MWorkflow>();
                String           oldKey = "";
                String           newKey = null;
                DataSet          ds     = null;
                try
                {
                    ds = DataBase.DB.ExecuteDataset(sql, null, null);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        DataRow   rs = ds.Tables[0].Rows[i];
                        MWorkflow wf = new MWorkflow(ctx, rs, null);
                        newKey = "C" + wf.GetAD_Client_ID() + "T" + wf.GetAD_Table_ID();
                        if (!newKey.Equals(oldKey) && list.Count > 0)
                        {
                            MWorkflow[] wfs = new MWorkflow[list.Count];
                            wfs = list.ToArray();
                            _cacheDocValue.Add(oldKey, wfs);
                            list = new List <MWorkflow>();
                        }
                        oldKey = newKey;
                        list.Add(wf);
                    }
                    ds = null;
                }
                catch (Exception e)
                {
                    _log.Log(Level.SEVERE, sql, e);
                }
                //  Last one
                if (list.Count > 0)
                {
                    MWorkflow[] wfs = new MWorkflow[list.Count];
                    wfs = list.ToArray();
                    _cacheDocValue.Add(oldKey, wfs);
                }
                _log.Config("#" + _cacheDocValue.Count);
            }
            //	Look for Entry
            MWorkflow[] retValue = (MWorkflow[])_cacheDocValue[key];
            return(retValue);
        }
Пример #6
0
        /// <summary>
        /// Process
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            MWorkflow WF = MWorkflow.Get(GetCtx(), p_AD_Worlflow_ID);

            log.Info("WF=" + WF);
            String msg = WF.Validate();

            WF.Save();
            if (msg.Length > 0)
            {
                throw new Exception(Utility.Msg.ParseTranslation(GetCtx(), "WorflowNotValid") + " - " + msg);
            }
            return(WF.IsValid() ? "@OK@" : "@Error@");
        }
Пример #7
0
        /// <summary>
        /// Get Workflow from Cache
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="AD_Workflow_ID">id</param>
        /// <returns>workflow</returns>
        public static MWorkflow Get(Ctx ctx, int AD_Workflow_ID)
        {
            int       key      = AD_Workflow_ID;
            MWorkflow retValue = _cache[key];

            if (retValue != null)
            {
                return(retValue);
            }
            retValue = new MWorkflow(ctx, AD_Workflow_ID, null);
            if (retValue.Get_ID() != 0)
            {
                _cache.Add(key, retValue);
            }
            return(retValue);
        }
        /// <summary>
        ///Test Start condition
        /// </summary>
        /// <param name="wf">workflow</param>
        /// <param name="document">document</param>
        /// <returns>true if WF should be started</returns>
        private bool TestStart(MWorkflow wf, PO document)
        {
            bool   retValue = false;
            String logic    = wf.GetDocValueLogic();

            logic = logic.Substring(4);         //	"SQL="
            String tableName = document.Get_TableName();

            String[] keyColumns = document.Get_KeyColumns();
            if (keyColumns.Length != 1)
            {
                //this is notice for column length
                log.Severe("Tables with more then one key column not supported - "
                           + tableName + " = " + keyColumns.Length);
                return(false);
            }
            String        keyColumn = keyColumns[0];
            StringBuilder sql       = new StringBuilder("SELECT ")
                                      .Append(keyColumn).Append(" FROM ").Append(tableName)
                                      .Append(" WHERE AD_Client_ID=" + wf.GetAD_Client_ID() + " AND ")                    //	#1
                                      .Append(keyColumn).Append("=" + document.Get_ID() + " AND ")                        //	#2
                                      .Append(logic)
                                                                                                                          //	Duplicate Open Workflow test
                                      .Append(" AND NOT EXISTS (SELECT * FROM AD_WF_Process wfp ")
                                      .Append("WHERE wfp.AD_Table_ID=" + document.Get_Table_ID() + " AND wfp.Record_ID=") //	#3
                                      .Append(tableName).Append(".").Append(keyColumn)
                                      .Append(" AND wfp.AD_Workflow_ID=" + wf.GetAD_Workflow_ID())                        //	#4
                                      .Append(" AND SUBSTR(wfp.WFState,1,1)='O')");
            DataSet ds = null;

            try
            {
                ds = DataBase.DB.ExecuteDataset(sql.ToString(), null, document.Get_Trx());
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    retValue = true;
                }
                ds = null;
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, "Logic=" + logic + " - SQL=" + sql.ToString(), e);
            }
            return(retValue);
        }
Пример #9
0
 /// <summary>
 ///Get Workflow
 /// </summary>
 /// <returns>workflow</returns>
 public MWorkflow GetWorkflow()
 {
     return(MWorkflow.Get(GetCtx(), GetAD_Workflow_ID()));
 }
        /// <summary>
        /// Process Document Value Workflow
        /// </summary>
        /// <param name="document">document</param>
        /// <param name="AD_Table_ID">table</param>
        /// <returns>true if WF started</returns>
        public bool Process(PO document, int AD_Table_ID)
        {
            _noCalled++;
            MWorkflow[] wfs = MWorkflow.GetDocValue(document.GetCtx(),
                                                    document.GetAD_Client_ID(), AD_Table_ID);
            if (wfs == null || wfs.Length == 0)
            {
                return(false);
            }

            bool 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
                bool 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;
                }

                if (document.Get_Trx() != null)
                {
                    ManageSkippedWF.Add(document.Get_Trx().SetUniqueTrxName(Trx.CreateTrxName("WFDV")), document);
                    log.Severe("Not started: " + wf);
                    continue;
                }
                //	Start Workflow
                log.Fine(logic);
                int         AD_Process_ID = 305;        //	HARDCODED
                ProcessInfo pi            = new ProcessInfo(wf.GetName(), AD_Process_ID, AD_Table_ID, document.Get_ID());
                pi.SetAD_User_ID(document.GetCtx().GetAD_User_ID());
                pi.SetAD_Client_ID(document.GetAD_Client_ID());

                // vinay bhatt for window id
                pi.SetAD_Window_ID(document.GetAD_Window_ID());
                //

                wf.GetCtx().SetContext("#AD_Client_ID", pi.GetAD_Client_ID().ToString());
                if (wf.Start(pi) != null)
                {
                    log.Config(wf.GetName());
                    _noStarted++;
                    started = true;
                }
            }
            return(started);
        }