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
.BeanNameAware
;
14 import org
.springframework
.beans
.factory
.InitializingBean
;
15 import org
.springframework
.validation
.MapBindingResult
;
17 public class SimpleExecutionFlow
implements ExecutionFlow
, InitializingBean
,
19 private ExecutionSpec executionSpec
= new SimpleExecutionSpec();
20 private String name
= null;
21 private Map
<String
, Object
> attributes
= new HashMap
<String
, Object
>();
22 private List
<Executable
> executables
= new ArrayList
<Executable
>();
24 private final String uuid
= UUID
.randomUUID().toString();
26 public void execute() {
27 for (Executable executable
: executables
) {
32 public void afterPropertiesSet() throws Exception
{
33 // Validate execution specs
34 if (executionSpec
== null)
37 MapBindingResult errors
= new MapBindingResult(attributes
, "execution#"
39 for (String key
: executionSpec
.getAttributes().keySet()) {
40 ExecutionSpecAttribute executionSpecAttr
= executionSpec
41 .getAttributes().get(key
);
42 if (!attributes
.containsKey(key
)) {
43 Object defaultValue
= executionSpecAttr
.getValue();
44 if (defaultValue
== null)
45 errors
.rejectValue(key
, "Not set and no default value");
47 attributes
.put(key
, defaultValue
);
48 } else {// contains key
49 Object obj
= attributes
.get(key
);
50 if (executionSpecAttr
instanceof RefSpecAttribute
) {
51 RefSpecAttribute rsa
= (RefSpecAttribute
) executionSpecAttr
;
52 Class targetClass
= rsa
.getTargetClass();
53 if (!targetClass
.isAssignableFrom(obj
.getClass())) {
55 + " not compatible with target class "
62 if (errors
.hasErrors())
63 throw new SlcException("Could not prepare execution flow: "
67 public void setBeanName(String name
) {
71 public void setExecutables(List
<Executable
> executables
) {
72 this.executables
= executables
;
75 public void setExecutionSpec(ExecutionSpec executionSpec
) {
76 this.executionSpec
= executionSpec
;
79 public void setAttributes(Map
<String
, Object
> attributes
) {
80 this.attributes
= attributes
;
83 public Map
<String
, Object
> getAttributes() {
87 public String
getUuid() {
91 public ExecutionSpec
getExecutionSpec() {
95 public String
toString() {
96 return new StringBuffer("Flow ").append(name
).toString();// .append(" [#")
97 // .append(uuid).append(']').toString();