[ 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,7 +113,7 @@ public class Scheduler extends AdempiereServer
//
ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_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_PInstance_ID(pInstance.getAD_PInstance_ID());
if (!process.processIt(pi, m_trx) && pi.getClassName() != null)
@ -127,8 +127,18 @@ public class Scheduler extends AdempiereServer
File report = re.getPDF();
// Notice
int AD_Message_ID = 884; // HARDCODED SchedulerResult
MUser from = new MUser(getCtx(), pi.getAD_User_ID(), null);
Integer[] userIDs = m_model.getRecipientAD_User_IDs();
for (int i = 0; i < userIDs.length; i++)
{
MUser user = new MUser(getCtx(), userIDs[i].intValue(), null);
String type = user.getNotificationType();
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 (notice)
{
MNote note = new MNote(getCtx(),
AD_Message_ID, userIDs[i].intValue(), m_trx.getTrxName());
@ -145,6 +155,12 @@ public class Scheduler extends AdempiereServer
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();
} // runReport
@ -167,12 +183,14 @@ public class Scheduler extends AdempiereServer
//
ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_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_PInstance_ID(pInstance.getAD_PInstance_ID());
//notify supervisor if error
MUser from = new MUser(getCtx(), pi.getAD_User_ID(), null);
//notify supervisor if error
if ( !process.processIt(pi, m_trx) )
{
int supervisor = m_model.getSupervisor_ID();
@ -184,6 +202,10 @@ public class Scheduler extends AdempiereServer
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 || notice)
ProcessInfoUtil.setLogFromDB(pi);
if (email)
{
MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID());
@ -192,7 +214,7 @@ public class Scheduler extends AdempiereServer
if (notice) {
int AD_Message_ID = 442; //ProcessRunError
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.setTextMsg(pi.getSummary());
//note.setDescription();
@ -204,6 +226,9 @@ public class Scheduler extends AdempiereServer
else
{
Integer[] userIDs = m_model.getRecipientAD_User_IDs();
if (userIDs.length > 0)
{
ProcessInfoUtil.setLogFromDB(pi);
for (int i = 0; i < userIDs.length; i++)
{
MUser user = new MUser(getCtx(), userIDs[i].intValue(), null);
@ -212,6 +237,7 @@ public class Scheduler extends AdempiereServer
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());
@ -220,7 +246,7 @@ public class Scheduler extends AdempiereServer
if (notice) {
int AD_Message_ID = 441; //ProcessOK
MNote note = new MNote(getCtx(),
AD_Message_ID, userIDs[i].intValue(), m_trx.getTrxName());
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();
@ -229,9 +255,23 @@ public class Scheduler extends AdempiereServer
}
}
}
}
return pi.getSummary();
} // 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
* @param pInstance process instance