Beispiel #1
0
        }       //	setPriority

        private void SendAlerts()
        {
            int    count       = 0;
            int    countEMails = 0;
            String sql         = "";

            //	Alert over Priority
            if (m_model.GetAlertOverPriority() > 0)
            {
                sql = "SELECT * "
                      + "FROM AD_WF_Activity a "
                      + "WHERE Processed='N' AND WFState='OS'"  //	suspended
                      + " AND Priority >= @Priority"            //	##1
                      + " AND (DateLastAlert IS NULL";
                if (m_model.GetRemindDays() > 0)
                {
                    sql += " OR (DateLastAlert+" + m_model.GetRemindDays()
                           + ") < SysDate";
                }
                sql += ") AND EXISTS (SELECT * FROM AD_Workflow wf "
                       + " INNER JOIN AD_WF_Node wfn ON (wf.AD_Workflow_ID=wfn.AD_Workflow_ID) "
                       + "WHERE a.AD_WF_Node_ID=wfn.AD_WF_Node_ID"
                       + " AND wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=@AD_WorkflowProcessor_ID)";



                try
                {
                    SqlParameter[] param = new SqlParameter[2];
                    param[0] = new SqlParameter("@Priority", m_model.GetAlertOverPriority());
                    param[1] = new SqlParameter("@AD_WorkflowProcessor_ID", m_model.GetAD_WorkflowProcessor_ID());

                    DataSet ds = DB.ExecuteDataset(sql, param);
                    foreach (DataRow dr in  ds.Tables[0].Rows)
                    {
                        MWFActivity activity = new MWFActivity(GetCtx(), dr, null);
                        bool        escalate = activity.GetDateLastAlert() != null;
                        countEMails += SendEmail(activity, "ActivityOverPriority", escalate, true);
                        activity.SetDateLastAlert(CommonFunctions.CovertMilliToDate(CommonFunctions.CurrentTimeMillis()));
                        activity.Save();
                        count++;
                    }
                }
                catch (SqlException e)
                {
                    log.Log(Level.SEVERE, "(Priority) - " + sql, e);
                }
                m_summary.Append("OverPriority #").Append(count);
                if (countEMails > 0)
                {
                    m_summary.Append(" (").Append(countEMails).Append(" EMail)");
                }
                m_summary.Append(" - ");
            }   //	Alert over Priority

            /**
             *  Over End Wait
             */
            sql = "SELECT * "
                  + "FROM AD_WF_Activity a "
                  + "WHERE Processed='N' AND WFState='OS'"      //	suspended
                  + " AND EndWaitTime > SysDate"
                  + " AND (DateLastAlert IS NULL";
            if (m_model.GetRemindDays() > 0)
            {
                sql += " OR (DateLastAlert+" + m_model.GetRemindDays()
                       + ") < SysDate";
            }
            sql += ") AND EXISTS (SELECT * FROM AD_Workflow wf "
                   + " INNER JOIN AD_WF_Node wfn ON (wf.AD_Workflow_ID=wfn.AD_Workflow_ID) "
                   + "WHERE a.AD_WF_Node_ID=wfn.AD_WF_Node_ID"
                   + " AND wfn.Action<>'Z'"     //	not sleeping
                   + " AND wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=@AD_WorkflowProcessor_ID)";

            count       = 0;
            countEMails = 0;
            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@AD_WorkflowProcessor_ID", m_model.GetAD_WorkflowProcessor_ID());
                DataSet ds = DB.ExecuteDataset(sql, param);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    MWFActivity activity = new MWFActivity(GetCtx(), dr, null);
                    bool        escalate = activity.GetDateLastAlert() != null;
                    countEMails += SendEmail(activity, "ActivityEndWaitTime", escalate, false);
                    activity.SetDateLastAlert(CommonFunctions.CovertMilliToDate(CommonFunctions.CurrentTimeMillis()));
                    activity.Save();
                    count++;
                }
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, "(EndWaitTime) - " + sql, e);
            }
            m_summary.Append("EndWaitTime #").Append(count);
            if (countEMails > 0)
            {
                m_summary.Append(" (").Append(countEMails).Append(" EMail)");
            }
            m_summary.Append(" - ");

            /**
             *  Send inactivity alerts
             */
            if (m_model.GetInactivityAlertDays() > 0)
            {
                sql = "SELECT * "
                      + "FROM AD_WF_Activity a "
                      + "WHERE Processed='N' AND WFState='OS'"  //	suspended
                      + " AND (Updated+" + m_model.GetInactivityAlertDays() + ") < SysDate"
                      + " AND (DateLastAlert IS NULL";
                if (m_model.GetRemindDays() > 0)
                {
                    sql += " OR (DateLastAlert+" + m_model.GetRemindDays()
                           + ") < SysDate";
                }
                sql += ") AND EXISTS (SELECT * FROM AD_Workflow wf "
                       + " INNER JOIN AD_WF_Node wfn ON (wf.AD_Workflow_ID=wfn.AD_Workflow_ID) "
                       + "WHERE a.AD_WF_Node_ID=wfn.AD_WF_Node_ID"
                       + " AND wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=@AD_WorkflowProcessor_ID)";

                count       = 0;
                countEMails = 0;
                try
                {
                    SqlParameter[] param = new SqlParameter[1];
                    param[0] = new SqlParameter("@AD_WorkflowProcessor_ID", m_model.GetAD_WorkflowProcessor_ID());
                    DataSet ds = DB.ExecuteDataset(sql, param);
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        MWFActivity activity = new MWFActivity(GetCtx(), dr, null);
                        bool        escalate = activity.GetDateLastAlert() != null;
                        countEMails += SendEmail(activity, "ActivityInactivity",
                                                 escalate, false);
                        activity.SetDateLastAlert(CommonFunctions.CovertMilliToDate(CommonFunctions.CurrentTimeMillis()));
                        activity.Save();
                        count++;
                    }
                }
                catch (SqlException e)
                {
                    log.Log(Level.SEVERE, "(Inactivity): " + sql, e);
                }
                m_summary.Append("Inactivity #").Append(count);
                if (countEMails > 0)
                {
                    m_summary.Append(" (").Append(countEMails).Append(" EMail)");
                }
                m_summary.Append(" - ");
            }   //	Inactivity
        }       //	sendAlerts