From dac8c6efe1152245042261cb716f2b5bc078ea24 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Thu, 7 May 2009 17:05:03 +0000 Subject: [PATCH] Make attachments more robust git-svn-id: https://svn.argeo.org/slc/trunk@2426 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- demo/pom.xml | 2 +- .../org.argeo.slc.demo.basic/conf/basic.xml | 3 +- .../argeo/slc/execution/ExecutionContext.java | 24 +++++----- .../org/argeo/slc/hibernate/cache/ehcache.xml | 5 +++ .../execution/FileExecutionResources.java | 44 ++++++++++++++----- .../core/execution/MapExecutionContext.java | 27 +++++++----- 6 files changed, 70 insertions(+), 35 deletions(-) diff --git a/demo/pom.xml b/demo/pom.xml index c7df955a2..8c80dd126 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -62,7 +62,7 @@ -Xmx256m - 0 + 8000 org.argeo.dep.osgi.catalina.start, diff --git a/demo/site/org.argeo.slc.demo.basic/conf/basic.xml b/demo/site/org.argeo.slc.demo.basic/conf/basic.xml index e8f675d1e..0e7b93daf 100644 --- a/demo/site/org.argeo.slc.demo.basic/conf/basic.xml +++ b/demo/site/org.argeo.slc.demo.basic/conf/basic.xml @@ -64,8 +64,7 @@ - - + diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionContext.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionContext.java index 0176d0063..113755af0 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionContext.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionContext.java @@ -1,27 +1,31 @@ package org.argeo.slc.execution; +import java.util.Date; import java.util.Map; public interface ExecutionContext { - + /** * @param name * @return null if no object is found */ public Object findScopedObject(String name); - + public void addScopedObject(String name, Object obj); - + public String getUuid(); - + public void enterFlow(ExecutionFlow executionFlow); - + public void leaveFlow(ExecutionFlow executionFlow); - + public Object getVariable(String key); - + public Object findVariable(String key); - - //TODO: replace with setVariable(String Key, Object value) - public void addVariables(Map variablesToAdd); + + // TODO: replace with setVariable(String Key, Object value) + public void addVariables( + Map variablesToAdd); + + public Date getCreationDate(); } diff --git a/runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/cache/ehcache.xml b/runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/cache/ehcache.xml index 7cb97e189..2aa369ab4 100644 --- a/runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/cache/ehcache.xml +++ b/runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/cache/ehcache.xml @@ -46,4 +46,9 @@ + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java index e35ff0014..171e0b2a1 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java @@ -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; + } + } diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/MapExecutionContext.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/MapExecutionContext.java index c985fd1dc..5d26c52b4 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/MapExecutionContext.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/MapExecutionContext.java @@ -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 stack = new Stack(); // TODO: make it thread safe? private final Map variables = new HashMap(); private final String uuid = UUID.randomUUID().toString(); - - public void addVariables(Map variablesToAdd) { + + private final Date creationDate = new Date(); + + public void addVariables( + Map variablesToAdd) { variables.putAll(variablesToAdd); } @@ -40,7 +43,7 @@ public class MapExecutionContext implements ExecutionContext { Map 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 scopedObjects = new HashMap(); -- 2.39.2