* 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;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.ldap.*;
import org.compiere.model.*;
import org.compiere.util.*;
import org.compiere.wf.*;
import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.ldap.LdapProcessor;
import org.compiere.model.AdempiereProcessor;
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

View File

@ -19,14 +19,28 @@ package org.compiere.server;
import it.sauronsoftware.cron4j.Predictor;
import it.sauronsoftware.cron4j.SchedulingPattern;
import java.io.*;
import java.math.*;
import java.sql.*;
import java.util.logging.*;
import org.compiere.model.*;
import org.compiere.print.*;
import org.compiere.process.*;
import org.compiere.util.*;
import java.io.File;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.logging.Level;
import org.compiere.model.MAttachment;
import org.compiere.model.MClient;
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(),
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)
@ -133,23 +147,36 @@ 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++)
{
MNote note = new MNote(getCtx(),
AD_Message_ID, userIDs[i].intValue(), m_trx.getTrxName());
note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
note.setTextMsg(m_model.getName());
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();
MUser user = new MUser(getCtx(), userIDs[i].intValue(), null);
boolean email = user.isNotificationEMail();
boolean notice = user.isNotificationNote();
if (notice)
{
MNote note = new MNote(getCtx(),
AD_Message_ID, userIDs[i].intValue(), m_trx.getTrxName());
note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
note.setTextMsg(m_model.getName());
note.setDescription(m_model.getDescription());
note.setRecord(AD_Table_ID, Record_ID);
note.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();
@ -173,37 +200,39 @@ 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();
if (supervisor > 0)
{
MUser user = new MUser(getCtx(), supervisor, 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);
boolean email = user.isNotificationEMail();
boolean notice = user.isNotificationNote();
if (email || notice)
ProcessInfoUtil.setLogFromDB(pi);
if (email)
{
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, m_model.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
client.sendEMail(from, user, process.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
}
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();
note.setRecord(X_AD_PInstance.Table_ID, pi.getAD_PInstance_ID());
note.setRecord(MPInstance.Table_ID, pi.getAD_PInstance_ID());
note.save();
}
}
@ -211,35 +240,49 @@ public class Scheduler extends AdempiereServer
else
{
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);
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 (email)
ProcessInfoUtil.setLogFromDB(pi);
for (int i = 0; i < userIDs.length; i++)
{
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, m_model.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
}
if (notice) {
int AD_Message_ID = 441; //ProcessOK
MNote note = new MNote(getCtx(),
AD_Message_ID, userIDs[i].intValue(), m_trx.getTrxName());
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();
MUser user = new MUser(getCtx(), userIDs[i].intValue(), null);
boolean email = user.isNotificationEMail();
boolean notice = user.isNotificationNote();
if (email)
{
MClient client = MClient.get(m_model.getCtx(), m_model.getAD_Client_ID());
client.sendEMail(from, user, process.getName(), pi.getSummary() + " " + pi.getLogInfo(), null);
}
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(MPInstance.Table_ID, pi.getAD_PInstance_ID());
note.save();
}
}
}
}
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