From fc91b00ffbeed46ca274955e72ef82dd83d12233 Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Fri, 16 Jan 2009 07:58:38 +0000 Subject: [PATCH] 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 ;) --- base/src/org/compiere/model/MAlertRule.java | 44 +++++++++++++++++++ .../org/compiere/server/AlertProcessor.java | 14 ++++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/base/src/org/compiere/model/MAlertRule.java b/base/src/org/compiere/model/MAlertRule.java index 6e82606a13..70756b336e 100644 --- a/base/src/org/compiere/model/MAlertRule.java +++ b/base/src/org/compiere/model/MAlertRule.java @@ -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 diff --git a/serverRoot/src/main/server/org/compiere/server/AlertProcessor.java b/serverRoot/src/main/server/org/compiere/server/AlertProcessor.java index 5b5d17a868..bb6cca3f2d 100644 --- a/serverRoot/src/main/server/org/compiere/server/AlertProcessor.java +++ b/serverRoot/src/main/server/org/compiere/server/AlertProcessor.java @@ -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 *
  • FR [ 1894573 ] Alert Processor Improvements + *
  • 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 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);