FR [ 2453882 ] Alert Processor : attached file name improvement
https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2453882&group_id=176962 minor improvement: at the end of the message i am adding date when the report was generated. Please help me with a review ;)
This commit is contained in:
parent
e65fadc597
commit
fc91b00ffb
|
@ -16,10 +16,16 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Util;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -30,6 +36,8 @@ import org.compiere.util.DB;
|
|||
*/
|
||||
public class MAlertRule extends X_AD_AlertRule
|
||||
{
|
||||
private static final long serialVersionUID = -1267260460210893262L;
|
||||
|
||||
/**
|
||||
* Standatd Constructor
|
||||
* @param ctx context
|
||||
|
@ -120,6 +128,42 @@ public class MAlertRule extends X_AD_AlertRule
|
|||
return finalSQL;
|
||||
} // getSql
|
||||
|
||||
/**
|
||||
* Create Report File
|
||||
* @param extension file extension
|
||||
* @return newly created File
|
||||
*/
|
||||
public File createReportFile(String extension)
|
||||
{
|
||||
if (Util.isEmpty(extension))
|
||||
{
|
||||
throw new IllegalArgumentException("Parameter extension cannot be empty");
|
||||
}
|
||||
String name = new SimpleDateFormat("yyyyMMddhhmm").format(new Timestamp(System.currentTimeMillis()))
|
||||
+"_"+Util.stripDiacritics(getName().trim());
|
||||
File file = null;
|
||||
try
|
||||
{
|
||||
file = new File(name+"."+extension);
|
||||
file.createNewFile();
|
||||
return file;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
file = null;
|
||||
}
|
||||
// Fallback
|
||||
String filePrefix = "Alert_"; // TODO: add AD_AlertRule.FileName (maybe)
|
||||
try
|
||||
{
|
||||
file = File.createTempFile(filePrefix, "."+extension);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new AdempiereException(e);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Level;
|
||||
|
@ -36,13 +37,13 @@ import org.compiere.model.MSysConfig;
|
|||
import org.compiere.model.MUser;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.TimeUtil;
|
||||
import org.compiere.util.Trx;
|
||||
import org.compiere.util.ValueNamePair;
|
||||
|
||||
|
||||
/**
|
||||
* Alert Processor
|
||||
*
|
||||
|
@ -51,6 +52,7 @@ import org.compiere.util.ValueNamePair;
|
|||
*
|
||||
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||
* <li>FR [ 1894573 ] Alert Processor Improvements
|
||||
* <li>FR [ 2453882 ] Alert Processor : attached file name improvement
|
||||
*/
|
||||
public class AlertProcessor extends AdempiereServer
|
||||
{
|
||||
|
@ -223,6 +225,13 @@ public class AlertProcessor extends AdempiereServer
|
|||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// Report footer - Date Generated
|
||||
DateFormat df = DisplayType.getDateFormat(DisplayType.DateTime);
|
||||
message.append("\n\n");
|
||||
message.append(Msg.translate(getCtx(), "Date")).append(" : ")
|
||||
.append(df.format(new Timestamp(System.currentTimeMillis())));
|
||||
|
||||
Collection<Integer> users = alert.getRecipientUsers();
|
||||
int countMail = notifyUsers(users, alert.getAlertSubject(), message.toString(), attachments);
|
||||
|
||||
|
@ -389,8 +398,7 @@ public class AlertProcessor extends AdempiereServer
|
|||
if (data.size() <= 1)
|
||||
return null;
|
||||
// File
|
||||
String filePrefix = "Alert_"; // TODO: add AD_AlertRule.FileName (maybe)
|
||||
File file = File.createTempFile(filePrefix, ".xls");
|
||||
File file = rule.createReportFile("xls");
|
||||
//
|
||||
ArrayExcelExporter exporter = new ArrayExcelExporter(getCtx(), data);
|
||||
exporter.export(file, null, false);
|
||||
|
|
Loading…
Reference in New Issue