1 package org
.argeo
.slc
.executionflow
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashMap
;
9 import org
.apache
.commons
.lang
.math
.RandomUtils
;
10 import org
.argeo
.slc
.SlcException
;
11 import org
.argeo
.slc
.process
.Executable
;
12 import org
.argeo
.slc
.test
.ExecutableTestRun
;
13 import org
.springframework
.beans
.factory
.InitializingBean
;
14 import org
.springframework
.validation
.MapBindingResult
;
16 public class SimpleExecutionFlow
implements ExecutionFlow
, InitializingBean
{
17 private static ThreadLocal
<ExecutionFlow
> executionFlow
= new ThreadLocal
<ExecutionFlow
>();
19 private ExecutionSpec executionSpec
;
20 private Map
<String
, Object
> attributes
= new HashMap
<String
, Object
>();
21 private List
<Executable
> executables
= new ArrayList
<Executable
>();
23 private final String uuid
= UUID
.randomUUID().toString();
25 public void execute() {
27 executionFlow
.set(this);
28 for (Executable executable
: executables
) {
32 executionFlow
.set(null);
36 public void afterPropertiesSet() throws Exception
{
37 // Validate execution specs
38 if (executionSpec
== null)
41 MapBindingResult errors
= new MapBindingResult(attributes
, "execution#"
43 for (String key
: executionSpec
.getAttributes().keySet()) {
44 ExecutionSpecAttribute executionSpecAttr
= executionSpec
45 .getAttributes().get(key
);
46 if (!attributes
.containsKey(key
)) {
47 Object defaultValue
= executionSpecAttr
.getValue();
48 if (defaultValue
== null)
49 errors
.rejectValue(key
, "Not set and no default value");
51 attributes
.put(key
, defaultValue
);
52 } else {// contains key
53 Object obj
= attributes
.get(key
);
54 if (executionSpecAttr
instanceof RefSpecAttribute
) {
55 RefSpecAttribute rsa
= (RefSpecAttribute
) executionSpecAttr
;
56 Class targetClass
= rsa
.getTargetClass();
57 if (!targetClass
.isAssignableFrom(obj
.getClass()))
58 errors
.rejectValue(key
,
59 "Not compatible with target class "
65 if (errors
.hasErrors())
66 throw new SlcException("Could not prepare execution flow: "
70 public void setExecutables(List
<Executable
> executables
) {
71 this.executables
= executables
;
74 public void setExecutionSpec(ExecutionSpec executionSpec
) {
75 this.executionSpec
= executionSpec
;
78 public void setAttributes(Map
<String
, Object
> attributes
) {
79 this.attributes
= attributes
;
82 public static ExecutionFlow
getCurrentExecutionFlow() {
83 return executionFlow
.get();
86 public Map
<String
, Object
> getAttributes() {
90 public String
getUuid() {