1 package org
.argeo
.slc
.core
.execution
;
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
.execution
.ExecutionFlow
;
12 import org
.argeo
.slc
.execution
.ExecutionSpec
;
13 import org
.argeo
.slc
.execution
.ExecutionSpecAttribute
;
14 import org
.argeo
.slc
.process
.Executable
;
15 import org
.argeo
.slc
.test
.ExecutableTestRun
;
16 import org
.springframework
.beans
.factory
.BeanNameAware
;
17 import org
.springframework
.beans
.factory
.InitializingBean
;
18 import org
.springframework
.validation
.MapBindingResult
;
20 public class SimpleExecutionFlow
implements ExecutionFlow
, InitializingBean
,
22 private ExecutionSpec executionSpec
= new SimpleExecutionSpec();
23 private String name
= null;
24 private Map
<String
, Object
> parameters
= new HashMap
<String
, Object
>();
25 private List
<Executable
> executables
= new ArrayList
<Executable
>();
27 public SimpleExecutionFlow() {
31 public SimpleExecutionFlow(Map
<String
, Object
> parameters
) {
32 this.parameters
.putAll(parameters
);
35 public void execute() {
36 for (Executable executable
: executables
) {
41 public void afterPropertiesSet() throws Exception
{
42 // Validate execution specs
43 if (executionSpec
== null)
46 MapBindingResult errors
= new MapBindingResult(parameters
, "execution#"
48 for (String key
: executionSpec
.getAttributes().keySet()) {
49 ExecutionSpecAttribute executionSpecAttr
= executionSpec
50 .getAttributes().get(key
);
51 if (!parameters
.containsKey(key
)) {
52 Object defaultValue
= executionSpecAttr
.getValue();
53 if (defaultValue
== null)
54 errors
.rejectValue(key
, "Not set and no default value");
56 parameters
.put(key
, defaultValue
);
57 } else {// contains key
58 Object obj
= parameters
.get(key
);
59 if (executionSpecAttr
instanceof RefSpecAttribute
) {
60 RefSpecAttribute rsa
= (RefSpecAttribute
) executionSpecAttr
;
61 // TODO: make sure this will not cause pb with OSGi
62 Class targetClass
= rsa
.getTargetClass();
63 if (!targetClass
.isAssignableFrom(obj
.getClass())) {
65 + " not compatible with target class "
72 if (errors
.hasErrors())
73 throw new SlcException("Could not prepare execution flow: "
77 public void setBeanName(String name
) {
81 public void setExecutables(List
<Executable
> executables
) {
82 this.executables
= executables
;
85 public void setExecutionSpec(ExecutionSpec executionSpec
) {
86 this.executionSpec
= executionSpec
;
89 public void setParameters(Map
<String
, Object
> attributes
) {
90 this.parameters
= attributes
;
93 public String
getName() {
97 public ExecutionSpec
getExecutionSpec() {
101 public Object
getParameter(String name
) {
102 if (parameters
.containsKey(name
)) {
103 return parameters
.get(name
);
105 if (executionSpec
.getAttributes().containsKey(name
)) {
106 ExecutionSpecAttribute esa
= executionSpec
.getAttributes().get(
108 if (esa
.getValue() != null)
109 return esa
.getValue();
111 throw new SlcException("Key " + name
112 + " is not defined in the specifications of "
116 throw new SlcException("Key " + name
+ " is not set as parameter in "
120 public String
toString() {
121 return new StringBuffer("Flow ").append(name
).toString();
124 public boolean equals(Object obj
) {
125 return ((ExecutionFlow
) obj
).getName().equals(name
);