} // sendAlert private int sendAlertToResponsible(MWFResponsible responsible, List <int> list, MWFProcess process, String subject, String message, FileInfo pdf) { int counter = 0; if (responsible.IsInvoker()) { ; } // Human else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Human.Equals(responsible.GetResponsibleType()) && responsible.GetAD_User_ID() != 0 && !list.Contains(responsible.GetAD_User_ID())) { if (m_client.SendEMail(responsible.GetAD_User_ID(), subject, message, pdf)) { counter++; } list.Add(responsible.GetAD_User_ID()); } // Org of the Document else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Organization.Equals(responsible.GetResponsibleType())) { PO document = process.GetPO(); if (document != null) { MOrgInfo org = MOrgInfo.Get(GetCtx(), document.GetAD_Org_ID(), null); if (org.GetSupervisor_ID() != 0 && !list.Contains(org.GetSupervisor_ID())) { if (m_client.SendEMail(org.GetSupervisor_ID(), subject, message, pdf)) { counter++; } list.Add(org.GetSupervisor_ID()); } } } // Role else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Role.Equals(responsible.GetResponsibleType()) && responsible.GetAD_Role_ID() != 0) { MUserRoles[] userRoles = MUserRoles.GetOfRole(GetCtx(), responsible.GetAD_Role_ID()); for (int i = 0; i < userRoles.Length; i++) { MUserRoles roles = userRoles[i]; if (!roles.IsActive()) { continue; } int AD_User_ID = roles.GetAD_User_ID(); if (!list.Contains(AD_User_ID)) { if (m_client.SendEMail(AD_User_ID, subject, message, pdf)) { counter++; } list.Add(AD_User_ID); } } } return(counter); } // sendAlertToResponsible
} // doWork /** * Process Alert * @param alert alert * @return true if processed */ private bool ProcessAlert(MAlert alert) { if (!alert.IsValid()) { log.Info("Invalid: " + alert); return(false); } log.Info("" + alert); m_recipients.Clear(); StringBuilder message = new StringBuilder(alert.GetAlertMessage()) .Append(Env.NL); // Context Ctx ctx = alert.GetCtx(); ctx.SetAD_Client_ID(alert.GetAD_Client_ID()); ctx.SetAD_Org_ID(alert.GetAD_Org_ID()); // bool valid = true; bool processed = false; MAlertRule[] rules = alert.GetRules(false); for (int i = 0; i < rules.Length; i++) { if (i > 0) { message.Append(Env.NL).Append("================================").Append(Env.NL); } //Trx trx = null; // assume r/o MAlertRule rule = rules[i]; if (!rule.IsValid()) { log.Config("Invalid: " + rule); continue; } log.Fine("" + rule); // Pre String sql = rule.GetPreProcessing(); if (sql != null && sql.Length > 0) { int no = DB.ExecuteQuery(sql); if (no == -1) { ValueNamePair error = VLogger.RetrieveError(); rule.SetErrorMsg("Pre=" + error.GetName()); m_errors.Append("Pre=" + error.GetName()); rule.SetIsValid(false); rule.Save(); valid = false; break; } } // Pre // The processing ctx.SetAD_Role_ID(0); ctx.SetAD_User_ID(0); sql = rule.GetSql(); if (alert.IsEnforceRoleSecurity() || alert.IsEnforceClientSecurity()) { int AD_Role_ID = alert.GetFirstAD_Role_ID(); if (AD_Role_ID == -1) { AD_Role_ID = alert.GetFirstUserAD_Role_ID(); } if (AD_Role_ID != -1) { String tableName = rule.GetTableName(); bool fullyQualified = MRole.SQL_FULLYQUALIFIED; if (Util.IsEmpty(tableName)) { fullyQualified = MRole.SQL_NOTQUALIFIED; } MRole role = MRole.Get(ctx, AD_Role_ID, 0, false); sql = role.AddAccessSQL(sql, tableName, fullyQualified, MRole.SQL_RO); ctx.SetAD_Role_ID(AD_Role_ID); } if (alert.GetFirstAD_User_ID() != -1) { ctx.SetAD_User_ID(alert.GetFirstAD_User_ID()); } } try { String text = ListSqlSelect(sql); if (text != null && text.Length > 0) { message.Append(text); processed = true; int index = text.IndexOf(":"); if (index > 0 && index < 5) { m_summary.Append(text.Substring(0, index)); } } } catch (Exception e) { rule.SetErrorMsg("Select=" + e.Message); m_errors.Append("Select=" + e.Message); rule.SetIsValid(false); rule.Save(); valid = false; break; } // Post sql = rule.GetPostProcessing(); if (sql != null && sql.Length > 0) { int no = DB.ExecuteQuery(sql); if (no == -1) { ValueNamePair error = VLogger.RetrieveError(); rule.SetErrorMsg("Post=" + error.GetName()); m_errors.Append("Post=" + error.GetName()); rule.SetIsValid(false); rule.Save(); valid = false; break; } } // Post } // for all rules // Update header if error if (!valid) { alert.SetIsValid(false); alert.Save(); return(false); } // Nothing to report if (!processed) { m_summary.Append(alert.GetName()).Append("=No Result - "); return(true); } // Send Message int countRecipient = 0; MAlertRecipient[] recipients = alert.GetRecipients(false); for (int i = 0; i < recipients.Length; i++) { MAlertRecipient recipient = recipients[i]; if (recipient.GetAD_User_ID() >= 0) // System == 0 { if (SendInfo(recipient.GetAD_User_ID(), alert, message.ToString())) { countRecipient++; } } if (recipient.GetAD_Role_ID() >= 0) // SystemAdministrator == 0 { MUserRoles[] urs = MUserRoles.GetOfRole(GetCtx(), recipient.GetAD_Role_ID()); for (int j = 0; j < urs.Length; j++) { MUserRoles ur = urs[j]; if (!ur.IsActive()) { continue; } if (SendInfo(ur.GetAD_User_ID(), alert, message.ToString())) { countRecipient++; } } } } m_summary.Append(alert.GetName()).Append(" (Recipients=").Append(countRecipient).Append(") - "); return(valid); } // processAlert