]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Introduce validation
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 18 Feb 2009 08:32:07 +0000 (08:32 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 18 Feb 2009 08:32:07 +0000 (08:32 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2153 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/EfLauncher.java
sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/ExecutionSpecAttribute.java
sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/RefSpecAttribute.java
sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionFlow.java
sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleExecutionSpec.java
sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/SimpleSpecAttribute.java
sandbox/argeo.slc.executionflow/src/slc/conf/testCases/basic-001.xml

index 98c191a3d26f24849d356bc05cdd49851f8e76b8..f46b0fe45d8d63c3a5cfc1f35c52c6690d3e63de 100644 (file)
@@ -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();
index de81c1ac879262526ef23ee7096e9cc0aad39a1c..9e293aebeefb54fd7355ce06a437d86090ecd8f4 100644 (file)
@@ -1,5 +1,5 @@
 package org.argeo.slc.executionflow;
 
-public interface ExecutionSpecAttribute<T> {
-       public T getValue();
+public interface ExecutionSpecAttribute {
+       public Object getValue();
 }
index bb22403b471d1017d4155053f680ab3a3f34556e..e5389398c8929889f7ca0e0054fd13c5af578c76 100644 (file)
@@ -1,14 +1,14 @@
 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;
        }
 
index d816419129577755264a300af367ca1d145ebd67..952bce0de2b8d6ee1f4b578d4ffa33a33762edf7 100644 (file)
@@ -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> executionFlow = new ThreadLocal<ExecutionFlow>();
@@ -17,7 +19,7 @@ public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean {
        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() {
@@ -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<Executable> executables) {
index f8eb969b8ead89fd8996596ed25674d1ca4cd9d6..c21ce22e9b14305ca36cf893c2a801dbe0c4c2e8 100644 (file)
@@ -17,7 +17,7 @@ public class SimpleExecutionSpec implements ExecutionSpec {
        }
 
        public Object createRef(String name) {
-               RefSpecAttribute<Object> refSpecAttribute = (RefSpecAttribute<Object>) attributes
+               RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes
                                .get(name);
                Class targetClass = refSpecAttribute.getTargetClass();
                ExecutionTargetSource targetSource = new ExecutionTargetSource();
index 9839b525fbcfdfaf73c20ea0b67256966484856b..b5e042cbd7eba63288101dca2149d2ff7200905f 100644 (file)
@@ -1,13 +1,13 @@
 package org.argeo.slc.executionflow;
 
-public class SimpleSpecAttribute<T> implements ExecutionSpecAttribute<T> {
-        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;
        }
 }
index 5f13829ab5673fb424f82052e0c9be2a1cb4243e..494f9789de8080116dc252faaf51c945b1e90e74 100644 (file)
@@ -8,12 +8,7 @@
        <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