]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java
Make attachments more robust
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / core / execution / FileExecutionResources.java
index e35ff0014c418bd1eb16e75b0bef814bb41d3f0d..171e0b2a16a023399854ad3410759ed64391c42b 100644 (file)
@@ -1,28 +1,39 @@
 package org.argeo.slc.core.execution;
 
 import java.io.File;
+import java.text.SimpleDateFormat;
 
 import org.argeo.slc.execution.ExecutionContext;
+import org.springframework.beans.factory.InitializingBean;
 import org.springframework.core.io.FileSystemResource;
 import org.springframework.core.io.Resource;
 
-public class FileExecutionResources implements ExecutionResources {
+public class FileExecutionResources implements ExecutionResources,
+               InitializingBean {
        private File baseDir;
        private ExecutionContext executionContext;
+       private String prefixDatePattern = "yyyyMMdd_HHmmss_";
+       private SimpleDateFormat sdf = null;
 
-       public FileExecutionResources() {
-               String osgiInstanceArea = System.getProperty("osgi.instance.area");
-               if (osgiInstanceArea != null) {
-                       if (osgiInstanceArea.startsWith("file:"))
-                               osgiInstanceArea = osgiInstanceArea.substring("file:".length());
-                       baseDir = new File(osgiInstanceArea + File.separator
-                                       + "executionResources");
-               }
+       public void afterPropertiesSet() throws Exception {
+               if (sdf == null)
+                       sdf = new SimpleDateFormat(prefixDatePattern);
 
                if (baseDir == null) {
-                       String tempDir = System.getProperty("java.io.tmpdir");
-                       baseDir = new File(tempDir + File.separator
-                                       + "slcExecutionResources");
+                       String osgiInstanceArea = System.getProperty("osgi.instance.area");
+                       if (osgiInstanceArea != null) {
+                               if (osgiInstanceArea.startsWith("file:"))
+                                       osgiInstanceArea = osgiInstanceArea.substring("file:"
+                                                       .length());
+                               baseDir = new File(osgiInstanceArea + File.separator
+                                               + "executionResources");
+                       }
+
+                       if (baseDir == null) {
+                               String tempDir = System.getProperty("java.io.tmpdir");
+                               baseDir = new File(tempDir + File.separator
+                                               + "slcExecutionResources");
+                       }
                }
        }
 
@@ -34,6 +45,7 @@ public class FileExecutionResources implements ExecutionResources {
 
        public File getFile(String relativePath) {
                File executionDir = new File(baseDir.getPath() + File.separator
+                               + sdf.format(executionContext.getCreationDate())
                                + executionContext.getUuid());
                if (!executionDir.exists())
                        executionDir.mkdirs();
@@ -48,4 +60,12 @@ public class FileExecutionResources implements ExecutionResources {
                this.executionContext = executionContext;
        }
 
+       public void setPrefixDatePattern(String prefixDatePattern) {
+               this.prefixDatePattern = prefixDatePattern;
+       }
+
+       public void setSdf(SimpleDateFormat sdf) {
+               this.sdf = sdf;
+       }
+
 }