Make attachments more robust
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 7 May 2009 17:05:03 +0000 (17:05 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 7 May 2009 17:05:03 +0000 (17:05 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2426 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

demo/pom.xml
demo/site/org.argeo.slc.demo.basic/conf/basic.xml
runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionContext.java
runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/cache/ehcache.xml
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/MapExecutionContext.java

index c7df955a207ba0e03c05947bbeaa21b15be90800..8c80dd1264596a38dfd78dee25247925ac496db2 100644 (file)
@@ -62,7 +62,7 @@
                                                        <jvmArgs>
                                                                <jvmArg>-Xmx256m</jvmArg>
                                                        </jvmArgs>
-                                                       <debug>0</debug>
+                                                       <debug>8000</debug>
                                                        <systemProperties>
                                                                <slc.osgi.start>
                                                                        org.argeo.dep.osgi.catalina.start,
index e8f675d1e71545e1d9c6f6b0b729a977772b7e84..0e7b93daf62275a973e115b10f92d7693b71cb6d 100644 (file)
@@ -64,8 +64,7 @@
                                        <property name="attachmentUploader" ref="attachmentUploader" />\r
                                        <property name="attachment">\r
                                                <bean parent="taskArg.attachment">\r
-                                                       <property name="name" value="myAttachment" />\r
-                                                       <property name="contentType" value="text/plain" />\r
+                                                       <property name="name" value="myAttachment.txt" />\r
                                                </bean>\r
                                        </property>\r
                                        <property name="resource" ref="basic.writeTo" />\r
index 0176d006378cc4d9687cfaf9e99797158fe30c9d..113755af0de84b65928f5d67861b64b11b5e615a 100644 (file)
@@ -1,27 +1,31 @@
 package org.argeo.slc.execution;\r
 \r
+import java.util.Date;\r
 import java.util.Map;\r
 \r
 public interface ExecutionContext {\r
-       \r
+\r
        /**\r
         * @param name\r
         * @return null if no object is found\r
         */\r
        public Object findScopedObject(String name);\r
-       \r
+\r
        public void addScopedObject(String name, Object obj);\r
-       \r
+\r
        public String getUuid();\r
-       \r
+\r
        public void enterFlow(ExecutionFlow executionFlow);\r
-       \r
+\r
        public void leaveFlow(ExecutionFlow executionFlow);\r
-       \r
+\r
        public Object getVariable(String key);\r
-       \r
+\r
        public Object findVariable(String key);\r
-       \r
-       //TODO: replace with setVariable(String Key, Object value)\r
-       public void addVariables(Map<? extends String, ? extends Object> variablesToAdd);\r
+\r
+       // TODO: replace with setVariable(String Key, Object value)\r
+       public void addVariables(\r
+                       Map<? extends String, ? extends Object> variablesToAdd);\r
+\r
+       public Date getCreationDate();\r
 }\r
index 7cb97e1890adc9a871a86d10622e8c141d8d7fcb..2aa369ab4258311defc668abe89ac6199ab33ca2 100644 (file)
@@ -46,4 +46,9 @@
        <cache name="org.argeo.slc.runtime.SlcAgentDescriptor"
                maxElementsInMemory="100" />
 
+       <cache name="org.argeo.slc.core.attachment.SimpleAttachment"
+               maxElementsInMemory="100000" />
+       <cache name="org.argeo.slc.core.test.tree.TreeTestResult.attachments"
+               maxElementsInMemory="100000" />
+
 </ehcache>
\ No newline at end of file
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;
+       }
+
 }
index c985fd1dc7a5d5c2a432f9fe19b45e6cbd75a419..5d26c52b42fd3d0bbda91618805173d8e9bff9ef 100644 (file)
@@ -1,5 +1,6 @@
 package org.argeo.slc.core.execution;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Stack;
@@ -17,15 +18,17 @@ import org.springframework.beans.factory.ObjectFactory;
 public class MapExecutionContext implements ExecutionContext {
        private final static Log log = LogFactory.getLog(MapExecutionContext.class);
 
-
        private final Stack<ExecutionFlowRuntime> stack = new Stack<ExecutionFlowRuntime>();
 
        // TODO: make it thread safe?
        private final Map<String, Object> variables = new HashMap<String, Object>();
 
        private final String uuid = UUID.randomUUID().toString();
-       
-       public void addVariables(Map<? extends String, ? extends Object> variablesToAdd) {
+
+       private final Date creationDate = new Date();
+
+       public void addVariables(
+                       Map<? extends String, ? extends Object> variablesToAdd) {
                variables.putAll(variablesToAdd);
        }
 
@@ -40,7 +43,7 @@ public class MapExecutionContext implements ExecutionContext {
                Map<String, ExecutionSpecAttribute> specAttrs = executionFlow
                                .getExecutionSpec().getAttributes();
                for (String key : specAttrs.keySet()) {
-                       //ExecutionSpecAttribute esa = specAttrs.get(key);
+                       // ExecutionSpecAttribute esa = specAttrs.get(key);
                        if (executionFlow.isSetAsParameter(key)) {
                                runtime.getLocalVariables().put(key,
                                                executionFlow.getParameter(key));
@@ -61,12 +64,12 @@ public class MapExecutionContext implements ExecutionContext {
 
        public Object findVariable(String key) {
                Object obj = null;
-               
+
                // Look if the variable is set in the global execution variables
                // (i.e. the variable was overridden)
                if (variables.containsKey(key))
-                       obj = variables.get(key);               
-               
+                       obj = variables.get(key);
+
                // if the variable was not found, look in the stack starting at the
                // upper flows
                if (obj == null) {
@@ -103,12 +106,12 @@ public class MapExecutionContext implements ExecutionContext {
                leftEf.getLocalVariables().clear();
 
        }
-       
+
        public void addScopedObject(String name, Object obj) {
-               //TODO: check that the object is not set yet ?
+               // TODO: check that the object is not set yet ?
                stack.peek().getScopedObjects().put(name, obj);
        }
-       
+
        /** return null if not found */
        public Object findScopedObject(String name) {
                Object obj = null;
@@ -125,6 +128,10 @@ public class MapExecutionContext implements ExecutionContext {
                return uuid;
        }
 
+       public Date getCreationDate() {
+               return creationDate;
+       }
+
        private static class ExecutionFlowRuntime {
                private final ExecutionFlow executionFlow;
                private final Map<String, Object> scopedObjects = new HashMap<String, Object>();