Delete temporal files after attaching or sending standard by email
authorCarlos Aristu <carlos.aristu@openbravo.com>
Wed, 13 May 2015 13:57:50 +0200
changeset 26747 13d27d8950e6
parent 26746 31a29dd8a050
child 26748 47b88136f675
Delete temporal files after attaching or sending standard by email
src/org/openbravo/erpCommon/utility/reporting/printing/PrintController.java
--- a/src/org/openbravo/erpCommon/utility/reporting/printing/PrintController.java	Wed May 13 09:05:35 2015 +0200
+++ b/src/org/openbravo/erpCommon/utility/reporting/printing/PrintController.java	Wed May 13 13:57:50 2015 +0200
@@ -500,6 +500,14 @@
         default:
           break;
         }
+        if (report.outputType.equals(OutputTypeEnum.ARCHIVE)) {
+          // Delete temporal reports generated for the returned report in case they have been
+          // attached also
+          File file = new File(report.getTargetLocation());
+          if (file.exists() && !file.isDirectory()) {
+            file.delete();
+          }
+        }
       }
     } catch (IOException e) {
       log4j.error(e.getMessage());
@@ -834,6 +842,13 @@
       String exceptionString = "Problems while sending the email" + exception;
       exceptionString = exceptionString.replace(exceptionClass, "");
       throw new ServletException(exceptionString);
+    } finally {
+      // Delete the temporal files generated for the email attachments
+      for (File attachment : attachments) {
+        if (attachment.exists() && !attachment.isDirectory()) {
+          attachment.delete();
+        }
+      }
     }
 
     // Store the email in the database