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 DefaultExecutionFlow
implements ExecutionFlow
, InitializingBean
,
22 private ExecutionSpec executionSpec
= new DefaultExecutionSpec();
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 DefaultExecutionFlow() {
31 public DefaultExecutionFlow(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 attr
= executionSpec
.getAttributes()
52 if (attr
.getIsParameter() && !isSetAsParameter(key
)) {
53 errors
.rejectValue(key
, "Parameter not set");
57 if (attr
.getIsFrozen() && !isSetAsParameter(key
)) {
58 errors
.rejectValue(key
, "Frozen but not set as parameter");
62 if (attr
.getIsHidden() && !isSetAsParameter(key
)) {
63 errors
.rejectValue(key
, "Hidden but not set as parameter");
68 * if (!parameters.containsKey(key)) { Object defaultValue =
69 * attr.getValue(); if (defaultValue == null)
70 * errors.rejectValue(key, "Not set and no default value"); else
71 * parameters.put(key, defaultValue); } else {// contains key Object
72 * obj = parameters.get(key); if (attr instanceof RefSpecAttribute)
73 * { RefSpecAttribute rsa = (RefSpecAttribute) attr; // TODO: make
74 * sure this will not cause pb with OSGi Class targetClass =
75 * rsa.getTargetClass(); if
76 * (!targetClass.isAssignableFrom(obj.getClass())) {
77 * errors.reject(key + " not compatible with target class " +
82 if (errors
.hasErrors())
83 throw new SlcException("Could not prepare execution flow: "
87 public void setBeanName(String name
) {
91 public void setExecutables(List
<Executable
> executables
) {
92 this.executables
= executables
;
95 public void setExecutionSpec(ExecutionSpec executionSpec
) {
96 this.executionSpec
= executionSpec
;
99 public void setParameters(Map
<String
, Object
> attributes
) {
100 this.parameters
= attributes
;
103 public String
getName() {
107 public ExecutionSpec
getExecutionSpec() {
108 return executionSpec
;
111 public Object
getParameter(String name
) {
112 if (parameters
.containsKey(name
)) {
113 return parameters
.get(name
);
115 if (executionSpec
.getAttributes().containsKey(name
)) {
116 ExecutionSpecAttribute esa
= executionSpec
.getAttributes().get(
118 if (esa
.getValue() != null)
119 return esa
.getValue();
121 throw new SlcException("Key " + name
122 + " is not defined in the specifications of "
126 throw new SlcException("Key " + name
+ " is not set as parameter in "
130 public Boolean
isSetAsParameter(String key
) {
131 return parameters
.containsKey(key
)
132 || (executionSpec
.getAttributes().containsKey(key
) && executionSpec
133 .getAttributes().get(key
).getValue() != null);
136 public String
toString() {
137 return new StringBuffer("Flow ").append(name
).toString();
140 public boolean equals(Object obj
) {
141 return ((ExecutionFlow
) obj
).getName().equals(name
);