package org.argeo.slc.executionflow;
-public class RefSpecAttribute<T> implements ExecutionSpecAttribute<T> {
+public class RefSpecAttribute implements ExecutionSpecAttribute {
private Class targetClass;
- private T value = null;
+ private Object value = null;
- public T getValue() {
+ public Object getValue() {
return value;
}
- public void setValue(T value) {
+ public void setValue(Object value) {
this.value = value;
}
import java.util.UUID;
import org.apache.commons.lang.math.RandomUtils;
+import org.argeo.slc.SlcException;
import org.argeo.slc.process.Executable;
import org.argeo.slc.test.ExecutableTestRun;
import org.springframework.beans.factory.InitializingBean;
+import org.springframework.validation.MapBindingResult;
public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean {
private static ThreadLocal<ExecutionFlow> executionFlow = new ThreadLocal<ExecutionFlow>();
private ExecutionSpec executionSpec;
private Map<String, Object> attributes = new HashMap<String, Object>();
private List<Executable> executables = new ArrayList<Executable>();
-
+
private final String uuid = UUID.randomUUID().toString();
public void execute() {
}
public void afterPropertiesSet() throws Exception {
- // TODO Auto-generated method stub
+ // Validate execution specs
+ if (executionSpec == null)
+ return;
+
+ MapBindingResult errors = new MapBindingResult(attributes, "execution#"
+ + getUuid());
+ for (String key : executionSpec.getAttributes().keySet()) {
+ ExecutionSpecAttribute executionSpecAttr = executionSpec
+ .getAttributes().get(key);
+ if (!attributes.containsKey(key)) {
+ Object defaultValue = executionSpecAttr.getValue();
+ if (defaultValue == null)
+ errors.rejectValue(key, "Not set and no default value");
+ else
+ attributes.put(key, defaultValue);
+ } else {// contains key
+ Object obj = attributes.get(key);
+ if (executionSpecAttr instanceof RefSpecAttribute) {
+ RefSpecAttribute rsa = (RefSpecAttribute) executionSpecAttr;
+ Class targetClass = rsa.getTargetClass();
+ if (!targetClass.isAssignableFrom(obj.getClass()))
+ errors.rejectValue(key,
+ "Not compatible with target class "
+ + targetClass);
+ }
+ }
+ }
+ if (errors.hasErrors())
+ throw new SlcException("Could not prepare execution flow: "
+ + errors.toString());
}
public void setExecutables(List<Executable> executables) {
<bean id="basic.001" parent="basic.executionFlowTemplate">\r
<property name="attributes">\r
<map>\r
- <entry key="testData1">\r
- <bean class="org.argeo.slc.core.test.BasicTestData">\r
- <property name="expected" value="toto" />\r
- <property name="reached" value="toto" />\r
- </bean>\r
- </entry>\r
+ <entry key="testData1" value-ref="basic.001.testData"/>\r
<entry key="testData2">\r
<bean class="org.argeo.slc.core.test.BasicTestData">\r
<property name="expected" value="tata" />\r
</property>\r
</bean>\r
\r
+ <bean id="basic.001.testData" class="org.argeo.slc.core.test.BasicTestData">\r
+ <property name="expected" value="toto" />\r
+ <property name="reached" value="toto" />\r
+ </bean>\r
+\r
+ <bean id="basic.001.testData2" class="org.argeo.slc.core.test.context.DefaultContextTestData">\r
+ </bean>\r
+\r
</beans>
\ No newline at end of file