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;
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;
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.");
}
}
}
try {
executionModule.execute(executionFlowDescriptor);
} catch (Exception e) {
+ //TODO: re-throw exception ?
log.error("Execution " + executionContext.getUuid()
+ " failed.", e);
}
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;
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
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
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