[ 2176020 ] Scheduler run report doesn't check user notification type

[ 2176046 ] Scheduler notification doesn't capture process info log
[ 2176024 ] Scheduler sometime fail to send email notification
This commit is contained in:
Heng Sin Low 2008-10-18 05:27:46 +00:00
parent 71fbbc6d3f
commit 2d85bf760a
1 changed files with 81 additions and 41 deletions

View File

@ -113,9 +113,9 @@ public class Scheduler extends AdempiereServer
// //
ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID(), ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID(),
AD_Table_ID, Record_ID); AD_Table_ID, Record_ID);
pi.setAD_User_ID(m_model.getUpdatedBy()); pi.setAD_User_ID(getAD_User_ID());
pi.setAD_Client_ID(m_model.getAD_Client_ID()); pi.setAD_Client_ID(m_model.getAD_Client_ID());
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID()); pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
if (!process.processIt(pi, m_trx) && pi.getClassName() != null) if (!process.processIt(pi, m_trx) && pi.getClassName() != null)
return "Process failed: (" + pi.getClassName() + ") " + pi.getSummary(); return "Process failed: (" + pi.getClassName() + ") " + pi.getSummary();
@ -127,23 +127,39 @@ public class Scheduler extends AdempiereServer
File report = re.getPDF(); File report = re.getPDF();
// Notice // Notice
int AD_Message_ID = 884; // HARDCODED SchedulerResult int AD_Message_ID = 884; // HARDCODED SchedulerResult
MUser from = new MUser(getCtx(), pi.getAD_User_ID(), null);
Integer[] userIDs = m_model.getRecipientAD_User_IDs(); Integer[] userIDs = m_model.getRecipientAD_User_IDs();
for (int i = 0; i < userIDs.length; i++) for (int i = 0; i < userIDs.length; i++)
{ {
MNote note = new MNote(getCtx(), MUser user = new MUser(getCtx(), userIDs[i].intValue(), null);
AD_Message_ID, userIDs[i].intValue(), m_trx.getTrxName()); String type = user.getNotificationType();
note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID()); boolean email = X_AD_User.NOTIFICATIONTYPE_EMail.equals(type) ||
note.setTextMsg(m_model.getName()); X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type);
note.setDescription(m_model.getDescription()); boolean notice = X_AD_User.NOTIFICATIONTYPE_Notice.equals(type) ||
note.setRecord(AD_Table_ID, Record_ID); X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type);
note.save();
// Attachment if (notice)
MAttachment attachment = new MAttachment (getCtx(), {
X_AD_Note.Table_ID, note.getAD_Note_ID(), m_trx.getTrxName()); MNote note = new MNote(getCtx(),
attachment.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID()); AD_Message_ID, userIDs[i].intValue(), m_trx.getTrxName());
attachment.addEntry(report); note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
attachment.setTextMsg(m_model.getName()); note.setTextMsg(m_model.getName());
attachment.save(); note.setDescription(m_model.getDescription());
note.setRecord(AD_Table_ID, Record_ID);
note.save();
// Attachment
MAttachment attachment = new MAttachment (getCtx(),
X_AD_Note.Table_ID, note.getAD_Note_ID(), m_trx.getTrxName());
attachment.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
attachment.addEntry(report);
attachment.setTextMsg(m_model.getName());
attachment.save();
}
if (email)
{
MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID());
client.sendEMail(from, user, m_model.getName(), m_model.getDescription(), report);
}
} }
// //
return pi.getSummary(); return pi.getSummary();
@ -167,12 +183,14 @@ public class Scheduler extends AdempiereServer
// //
ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID(), ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID(),
AD_Table_ID, Record_ID); AD_Table_ID, Record_ID);
pi.setAD_User_ID(m_model.getUpdatedBy()); int AD_User_ID = getAD_User_ID();
pi.setAD_User_ID(AD_User_ID);
pi.setAD_Client_ID(m_model.getAD_Client_ID()); pi.setAD_Client_ID(m_model.getAD_Client_ID());
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID()); pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
//notify supervisor if error
MUser from = new MUser(getCtx(), pi.getAD_User_ID(), null); MUser from = new MUser(getCtx(), pi.getAD_User_ID(), null);
//notify supervisor if error
if ( !process.processIt(pi, m_trx) ) if ( !process.processIt(pi, m_trx) )
{ {
int supervisor = m_model.getSupervisor_ID(); int supervisor = m_model.getSupervisor_ID();
@ -184,6 +202,10 @@ public class Scheduler extends AdempiereServer
X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type); X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type);
boolean notice = X_AD_User.NOTIFICATIONTYPE_Notice.equals(type) || boolean notice = X_AD_User.NOTIFICATIONTYPE_Notice.equals(type) ||
X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type); X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type);
if (email || notice)
ProcessInfoUtil.setLogFromDB(pi);
if (email) if (email)
{ {
MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID()); MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID());
@ -192,7 +214,7 @@ public class Scheduler extends AdempiereServer
if (notice) { if (notice) {
int AD_Message_ID = 442; //ProcessRunError int AD_Message_ID = 442; //ProcessRunError
MNote note = new MNote(getCtx(), MNote note = new MNote(getCtx(),
AD_Message_ID, supervisor, m_trx.getTrxName()); AD_Message_ID, supervisor, null);
note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID()); note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
note.setTextMsg(pi.getSummary()); note.setTextMsg(pi.getSummary());
//note.setDescription(); //note.setDescription();
@ -202,35 +224,53 @@ public class Scheduler extends AdempiereServer
} }
} }
else else
{ {
Integer[] userIDs = m_model.getRecipientAD_User_IDs(); Integer[] userIDs = m_model.getRecipientAD_User_IDs();
for (int i = 0; i < userIDs.length; i++) if (userIDs.length > 0)
{ {
MUser user = new MUser(getCtx(), userIDs[i].intValue(), null); ProcessInfoUtil.setLogFromDB(pi);
String type = user.getNotificationType(); for (int i = 0; i < userIDs.length; i++)
boolean email = X_AD_User.NOTIFICATIONTYPE_EMail.equals(type) ||
X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type);
boolean notice = X_AD_User.NOTIFICATIONTYPE_Notice.equals(type) ||
X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type);
if (email)
{ {
MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID()); MUser user = new MUser(getCtx(), userIDs[i].intValue(), null);
client.sendEMail(from, user, process.getName(), pi.getSummary() + " " + pi.getLogInfo(), null); String type = user.getNotificationType();
} boolean email = X_AD_User.NOTIFICATIONTYPE_EMail.equals(type) ||
if (notice) { X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type);
int AD_Message_ID = 441; //ProcessOK boolean notice = X_AD_User.NOTIFICATIONTYPE_Notice.equals(type) ||
MNote note = new MNote(getCtx(), X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type);
AD_Message_ID, userIDs[i].intValue(), m_trx.getTrxName());
note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID()); if (email)
note.setTextMsg(pi.getSummary()); {
//note.setDescription(); MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID());
note.setRecord(X_AD_PInstance.Table_ID, pi.getAD_PInstance_ID()); client.sendEMail(from, user, process.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
note.save(); }
if (notice) {
int AD_Message_ID = 441; //ProcessOK
MNote note = new MNote(getCtx(),
AD_Message_ID, userIDs[i].intValue(), null);
note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
note.setTextMsg(pi.getSummary());
//note.setDescription();
note.setRecord(X_AD_PInstance.Table_ID, pi.getAD_PInstance_ID());
note.save();
}
} }
} }
} }
return pi.getSummary(); return pi.getSummary();
} // runProcess } // runProcess
private int getAD_User_ID() {
int AD_User_ID;
if (m_model.getSupervisor_ID() > 0)
AD_User_ID = m_model.getSupervisor_ID();
else if (m_model.getUpdatedBy() > 0)
AD_User_ID = m_model.getUpdatedBy();
else if (m_model.getCreatedBy() > 0)
AD_User_ID = m_model.getCreatedBy();
else
AD_User_ID = 100; //fall back to SuperUser
return AD_User_ID;
}
/** /**
* Fill Parameter * Fill Parameter