* Fixed version mixed up in previous commit.

Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2956390
This commit is contained in:
Heng Sin Low 2010-02-23 13:20:41 +00:00
parent f537c99a87
commit c7b42af6dd
2 changed files with 120 additions and 63 deletions

View File

@ -16,13 +16,27 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.server; package org.compiere.server;
import java.sql.*; import java.sql.Timestamp;
import java.util.*; import java.util.Properties;
import java.util.logging.*; import java.util.logging.Level;
import org.compiere.ldap.*;
import org.compiere.model.*; import org.compiere.ldap.LdapProcessor;
import org.compiere.util.*; import org.compiere.model.AdempiereProcessor;
import org.compiere.wf.*; import org.compiere.model.AdempiereProcessor2;
import org.compiere.model.AdempiereProcessorLog;
import org.compiere.model.MAcctProcessor;
import org.compiere.model.MAlertProcessor;
import org.compiere.model.MClient;
import org.compiere.model.MIMPProcessor;
import org.compiere.model.MLdapProcessor;
import org.compiere.model.MRequestProcessor;
import org.compiere.model.MScheduler;
import org.compiere.model.MSystem;
import org.compiere.model.X_R_RequestProcessor;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
import org.compiere.wf.MWorkflowProcessor;
/** /**
* Adempiere Server Base * Adempiere Server Base

View File

@ -19,14 +19,28 @@ package org.compiere.server;
import it.sauronsoftware.cron4j.Predictor; import it.sauronsoftware.cron4j.Predictor;
import it.sauronsoftware.cron4j.SchedulingPattern; import it.sauronsoftware.cron4j.SchedulingPattern;
import java.io.*; import java.io.File;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.Timestamp;
import java.util.logging.*; import java.util.logging.Level;
import org.compiere.model.*;
import org.compiere.print.*; import org.compiere.model.MAttachment;
import org.compiere.process.*; import org.compiere.model.MClient;
import org.compiere.util.*; import org.compiere.model.MNote;
import org.compiere.model.MPInstance;
import org.compiere.model.MPInstancePara;
import org.compiere.model.MProcess;
import org.compiere.model.MScheduler;
import org.compiere.model.MSchedulerLog;
import org.compiere.model.MSchedulerPara;
import org.compiere.model.MUser;
import org.compiere.print.ReportEngine;
import org.compiere.process.ProcessInfo;
import org.compiere.process.ProcessInfoUtil;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
import org.compiere.util.Trx;
/** /**
@ -119,7 +133,7 @@ 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)
@ -133,23 +147,36 @@ 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()); boolean email = user.isNotificationEMail();
note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID()); boolean notice = user.isNotificationNote();
note.setTextMsg(m_model.getName());
note.setDescription(m_model.getDescription()); if (notice)
note.setRecord(AD_Table_ID, Record_ID); {
note.save(); MNote note = new MNote(getCtx(),
// Attachment AD_Message_ID, userIDs[i].intValue(), m_trx.getTrxName());
MAttachment attachment = new MAttachment (getCtx(), note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
X_AD_Note.Table_ID, note.getAD_Note_ID(), m_trx.getTrxName()); note.setTextMsg(m_model.getName());
attachment.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID()); note.setDescription(m_model.getDescription());
attachment.addEntry(report); note.setRecord(AD_Table_ID, Record_ID);
attachment.setTextMsg(m_model.getName()); note.save();
attachment.save(); // Attachment
MAttachment attachment = new MAttachment (getCtx(),
MNote.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();
@ -173,37 +200,39 @@ 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();
if (supervisor > 0) if (supervisor > 0)
{ {
MUser user = new MUser(getCtx(), supervisor, null); MUser user = new MUser(getCtx(), supervisor, null);
String type = user.getNotificationType(); boolean email = user.isNotificationEMail();
boolean email = X_AD_User.NOTIFICATIONTYPE_EMail.equals(type) || boolean notice = user.isNotificationNote();
X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type);
boolean notice = X_AD_User.NOTIFICATIONTYPE_Notice.equals(type) || if (email || notice)
X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.equals(type); 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());
// client.sendEMail(from, user, process.getName(), pi.getSummary() + " " + pi.getLogInfo(), null); client.sendEMail(from, user, process.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
client.sendEMail(from, user, m_model.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
} }
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();
note.setRecord(X_AD_PInstance.Table_ID, pi.getAD_PInstance_ID()); note.setRecord(MPInstance.Table_ID, pi.getAD_PInstance_ID());
note.save(); note.save();
} }
} }
@ -211,35 +240,49 @@ 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); boolean email = user.isNotificationEMail();
client.sendEMail(from, user, m_model.getName(), pi.getSummary() + " " + pi.getLogInfo(), null); boolean notice = user.isNotificationNote();
}
if (notice) { if (email)
int AD_Message_ID = 441; //ProcessOK {
MNote note = new MNote(getCtx(), MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID());
AD_Message_ID, userIDs[i].intValue(), m_trx.getTrxName()); client.sendEMail(from, user, process.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID()); }
note.setTextMsg(pi.getSummary()); if (notice) {
//note.setDescription(); int AD_Message_ID = 441; //ProcessOK
note.setRecord(X_AD_PInstance.Table_ID, pi.getAD_PInstance_ID()); MNote note = new MNote(getCtx(),
note.save(); 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(MPInstance.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
* @param pInstance process instance * @param pInstance process instance