From: Mathieu Baudier Date: Wed, 18 Feb 2009 08:32:07 +0000 (+0000) Subject: Introduce validation X-Git-Tag: argeo-slc-2.1.7~2146 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=d219191bc5879dc486e21d1ae05fc1d82a1ef5a5;p=gpl%2Fargeo-slc.git Introduce validation git-svn-id: https://svn.argeo.org/slc/trunk@2153 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/EfLauncher.java b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/EfLauncher.java index 98c191a3d..f46b0fe45 100644 --- a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/EfLauncher.java +++ b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/EfLauncher.java @@ -32,6 +32,7 @@ public class EfLauncher { FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext( script); // context.start(); + log.info("Context initialized"); ExecutionFlow main = (ExecutionFlow)context.getBean("main"); main.execute(); diff --git a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/ExecutionSpecAttribute.java b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/ExecutionSpecAttribute.java index de81c1ac8..9e293aebe 100644 --- a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/ExecutionSpecAttribute.java +++ b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/ExecutionSpecAttribute.java @@ -1,5 +1,5 @@ package org.argeo.slc.executionflow; -public interface ExecutionSpecAttribute { - public T getValue(); +public interface ExecutionSpecAttribute { + public Object getValue(); } diff --git a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/RefSpecAttribute.java b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/RefSpecAttribute.java index bb22403b4..e5389398c 100644 --- a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/RefSpecAttribute.java +++ b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/RefSpecAttribute.java @@ -1,14 +1,14 @@ package org.argeo.slc.executionflow; -public class RefSpecAttribute implements ExecutionSpecAttribute { +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; } diff --git a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionFlow.java b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionFlow.java index d81641912..952bce0de 100644 --- a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionFlow.java +++ b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionFlow.java @@ -7,9 +7,11 @@ import java.util.Map; 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 = new ThreadLocal(); @@ -17,7 +19,7 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean { private ExecutionSpec executionSpec; private Map attributes = new HashMap(); private List executables = new ArrayList(); - + private final String uuid = UUID.randomUUID().toString(); public void execute() { @@ -32,8 +34,37 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean { } 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 executables) { diff --git a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionSpec.java b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionSpec.java index f8eb969b8..c21ce22e9 100644 --- a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionSpec.java +++ b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionSpec.java @@ -17,7 +17,7 @@ public class SimpleExecutionSpec implements ExecutionSpec { } public Object createRef(String name) { - RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes + RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes .get(name); Class targetClass = refSpecAttribute.getTargetClass(); ExecutionTargetSource targetSource = new ExecutionTargetSource(); diff --git a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleSpecAttribute.java b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleSpecAttribute.java index 9839b525f..b5e042cbd 100644 --- a/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleSpecAttribute.java +++ b/sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleSpecAttribute.java @@ -1,13 +1,13 @@ package org.argeo.slc.executionflow; -public class SimpleSpecAttribute implements ExecutionSpecAttribute { - private T value = null; +public class SimpleSpecAttribute implements ExecutionSpecAttribute { + 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; } } diff --git a/sandbox/argeo.slc.executionflow/src/slc/conf/testCases/basic-001.xml b/sandbox/argeo.slc.executionflow/src/slc/conf/testCases/basic-001.xml index 5f13829ab..494f9789d 100644 --- a/sandbox/argeo.slc.executionflow/src/slc/conf/testCases/basic-001.xml +++ b/sandbox/argeo.slc.executionflow/src/slc/conf/testCases/basic-001.xml @@ -8,12 +8,7 @@ - - - - - - + @@ -24,4 +19,12 @@ + + + + + + + + \ No newline at end of file