]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Bug corrections in DefaultModulesManager and ExecutionContext
authorOlivier Capillon <olivier.capillon@gmail.com>
Thu, 12 Mar 2009 13:55:08 +0000 (13:55 +0000)
committerOlivier Capillon <olivier.capillon@gmail.com>
Thu, 12 Mar 2009 13:55:08 +0000 (13:55 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2257 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultModulesManager.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionContext.java
runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/DefaultModulesMangerTest.java
runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java

index ec53ca9af8d7edc4be06e0c443b26f7051ffbfbd..7da391a3796316697be997cedd10c944136e3b51 100644 (file)
@@ -1,10 +1,13 @@
 package org.argeo.slc.core.execution;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
 import org.argeo.slc.execution.ExecutionFlow;
 import org.argeo.slc.execution.ExecutionFlowDescriptor;
 import org.argeo.slc.execution.ExecutionModule;
@@ -23,8 +26,9 @@ public class DefaultModulesManager implements ExecutionModulesManager {
        protected ExecutionModule getExecutionModule(String moduleName, String version) {
                for (ExecutionModule moduleT : executionModules) {
                        if (moduleT.getName().equals(moduleName)) {
-                               // TODO: check version
-                               return moduleT;
+                               if(moduleT.getVersion().equals(version)) {
+                                       return moduleT;
+                               }
                        }
                }
                return null;
@@ -55,13 +59,35 @@ public class DefaultModulesManager implements ExecutionModulesManager {
                                        flow.getModuleVersion());
                        if(module != null) {
                                ExecutionContext executionContext = new ExecutionContext();
-                               executionContext.addVariables(slcExecution.getAttributes());
+                               
+                               // convert the values of flow.getFlowDescriptor()
+                               Map<String, Object> values = flow.getFlowDescriptor().getValues();
+                               
+                               Map<String, Object> convertedValues = new HashMap<String, Object>();
+                               
+                               for(String key : values.keySet()) {
+                                       Object value = values.get(key);
+                                       if(value instanceof PrimitiveValue) {
+                                               PrimitiveValue primitiveValue = (PrimitiveValue) value;
+
+                                               // TODO: check that the class of the the primitiveValue.value matches
+                                               // the primitiveValue.type
+                                               convertedValues.put(key, primitiveValue.getValue());
+                                       }
+                                       else if(value instanceof RefValue) {
+                                               RefValue refValue = (RefValue) value;
+                                               convertedValues.put(key, refValue.getLabel());
+                                       }
+                               }
+                               
+                               executionContext.addVariables(convertedValues);
                                ExecutionThread thread = new ExecutionThread(executionContext, flow.getFlowDescriptor(),
                                                module);
                                thread.start();
                        }
                        else {
-                               // throw exception ?
+                               throw new SlcException("ExecutionModule " + flow.getModuleName() + ", version " 
+                                               + flow.getModuleVersion() + " not found.");
                        }
                }
        }
@@ -85,6 +111,7 @@ public class DefaultModulesManager implements ExecutionModulesManager {
                        try {
                                executionModule.execute(executionFlowDescriptor);
                        } catch (Exception e) {
+                               //TODO: re-throw exception ?
                                log.error("Execution " + executionContext.getUuid()
                                                + " failed.", e);
                        }
index d6b69af8485494dbd18cf66e693af489af1ce515..61eb6721e920ae17c9b409a7ba87c2863fa9ec3b 100644 (file)
@@ -100,17 +100,21 @@ public class ExecutionContext {
 
        protected Object findVariable(String key) {
                Object obj = null;
-               for (int i = stack.size() - 1; i >= 0; i--) {
-                       if (stack.get(i).getLocalVariables().containsKey(key)) {
-                               obj = stack.get(i).getLocalVariables().get(key);
-                               break;
-                       }
-               }
-
-               // Look into global execution variables
+               
+               // Look if the variable is set in the global execution variables
+               // (i.e. the variable was overridden)
+               if (variables.containsKey(key))
+                       obj = variables.get(key);               
+               
+               // if the variable was not found, look in the stack starting at the
+               // upper flows
                if (obj == null) {
-                       if (variables.containsKey(key))
-                               obj = variables.get(key);
+                       for (int i = 0; i < stack.size(); i++) {
+                               if (stack.get(i).getLocalVariables().containsKey(key)) {
+                                       obj = stack.get(i).getLocalVariables().get(key);
+                                       break;
+                               }
+                       }
                }
 
                return obj;
index b3a48fd227a42ff12368b5c582f93ef51649c3fa..9ada76d0f24fb2746792b9b48fb3225a8ce525e0 100644 (file)
@@ -1,7 +1,9 @@
 package org.argeo.slc.core.execution;\r
 \r
 import java.util.ArrayList;\r
+import java.util.HashMap;\r
 import java.util.List;\r
+import java.util.Map;\r
 \r
 import org.argeo.slc.SlcException;\r
 import org.argeo.slc.execution.ExecutionFlowDescriptor;\r
@@ -29,6 +31,10 @@ public class DefaultModulesMangerTest extends AbstractSpringTestCase {
                flow.setModuleVersion("dummyversion");\r
                ExecutionFlowDescriptor executionFlowDescriptor = new ExecutionFlowDescriptor();\r
                executionFlowDescriptor.setName("main");\r
+               Map<String, Object> values = new HashMap<String, Object>();\r
+               values.put("testKey", new PrimitiveValue(\r
+                               PrimitiveSpecAttribute.TYPE_INTEGER, 22));\r
+               executionFlowDescriptor.setValues(values);\r
                flow.setFlowDescriptor(executionFlowDescriptor);\r
                realizedFlows.add(flow);\r
                execution.setRealizedFlows(realizedFlows);\r
index 4698e8148200ab1384c98cfadd5d8f59c7fa9546..8b4669b11988bb04266253346ba2ebaebfa0c70a 100644 (file)
@@ -19,14 +19,14 @@ public class ExecutionFlowTest extends AbstractSpringTestCase {
                configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");\r
                configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");\r
 \r
-/*             try {\r
+               try {\r
                        configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");\r
                        fail("Parameter not set - should be rejected.");\r
                } catch (BeanCreationException e) {\r
                        // exception expected\r
                        logException(e);\r
                }\r
-*/             \r
+               \r
 /*             try {\r
                        configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");\r
                        fail("Unknown parameter set - should be rejected.");\r