X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.simple%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2FDefaultExecutionFlow.java;h=91b4ae949c162612a8aa89f1db8d0a04c83ec8b9;hb=043edae6e81b1ef82dbc7c0990610e8658186ac3;hp=8c06dc579f62db2d01f4c1f70e335cc64ee7e3a6;hpb=14754f11d095508e561d9b27d7b3805557940bbc;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java index 8c06dc579..91b4ae949 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java @@ -4,9 +4,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.UUID; -import org.apache.commons.lang.math.RandomUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.argeo.slc.SlcException; import org.argeo.slc.core.structure.tree.TreeSPath; import org.argeo.slc.core.structure.tree.TreeSRegistry; @@ -16,13 +16,16 @@ import org.argeo.slc.execution.ExecutionSpec; import org.argeo.slc.execution.ExecutionSpecAttribute; import org.argeo.slc.structure.StructureAware; import org.argeo.slc.structure.StructureRegistry; -import org.argeo.slc.test.ExecutableTestRun; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.validation.MapBindingResult; public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean, - BeanNameAware { + BeanNameAware, StructureAware { + + private final static Log log = LogFactory + .getLog(DefaultExecutionFlow.class); + private ExecutionSpec executionSpec = new DefaultExecutionSpec(); private String name = null; private Map parameters = new HashMap(); @@ -30,26 +33,29 @@ public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean, private String path; private StructureRegistry registry = new TreeSRegistry(); - + public DefaultExecutionFlow() { - - } - - public DefaultExecutionFlow(Map parameters) { - this.parameters.putAll(parameters); + } + + public DefaultExecutionFlow(ExecutionSpec executionSpec) { + this.executionSpec = executionSpec; } - - public void execute() { - for (Executable executable : executables) { - executable.execute(); + + public DefaultExecutionFlow(ExecutionSpec executionSpec, Map parameters) { + // be sure to have an execution spec + this.executionSpec = (executionSpec == null) ? new DefaultExecutionSpec() : executionSpec; + + //only parameters contained in the executionSpec can be set + for(String parameter : parameters.keySet()) { + if(!executionSpec.getAttributes().containsKey(parameter)) { + throw new SlcException("Parameter " + parameter + " is not defined in the ExecutionSpec"); + } } - } - - public void afterPropertiesSet() throws Exception { - // Validate execution specs - if (executionSpec == null) - return; - + + // set the parameters + this.parameters.putAll(parameters); + + //check that all the required parameters are defined MapBindingResult errors = new MapBindingResult(parameters, "execution#" + getName()); for (String key : executionSpec.getAttributes().keySet()) { @@ -70,30 +76,22 @@ public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean, errors.rejectValue(key, "Hidden but not set as parameter"); break; } - - /* - * if (!parameters.containsKey(key)) { Object defaultValue = - * attr.getValue(); if (defaultValue == null) - * errors.rejectValue(key, "Not set and no default value"); else - * parameters.put(key, defaultValue); } else {// contains key Object - * obj = parameters.get(key); if (attr instanceof RefSpecAttribute) - * { RefSpecAttribute rsa = (RefSpecAttribute) attr; // TODO: make - * sure this will not cause pb with OSGi Class targetClass = - * rsa.getTargetClass(); if - * (!targetClass.isAssignableFrom(obj.getClass())) { - * errors.reject(key + " not compatible with target class " + - * targetClass); } } } - */ } if (errors.hasErrors()) throw new SlcException("Could not prepare execution flow: " - + errors.toString()); + + errors.toString()); + + + } - // if (path == null) { - // path = "/" + executionSpec.getName() + "/" + name; - // } + public void execute() { + for (Executable executable : executables) { + executable.execute(); + } + } + public void afterPropertiesSet() throws Exception { if (path != null) { for (Executable executable : executables) { if (executable instanceof StructureAware) { @@ -112,10 +110,6 @@ public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean, this.executables = executables; } - public void setExecutionSpec(ExecutionSpec executionSpec) { - this.executionSpec = executionSpec; - } - public void setParameters(Map attributes) { this.parameters = attributes; } @@ -128,22 +122,23 @@ public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean, return executionSpec; } - public Object getParameter(String name) { - if (parameters.containsKey(name)) { - return parameters.get(name); + public Object getParameter(String parameterName) { + if (parameters.containsKey(parameterName)) { + return parameters.get(parameterName); } else { - if (executionSpec.getAttributes().containsKey(name)) { + if (executionSpec.getAttributes().containsKey(parameterName)) { ExecutionSpecAttribute esa = executionSpec.getAttributes().get( - name); - if (esa.getValue() != null) + parameterName); + if (esa.getValue() != null) { return esa.getValue(); + } } else { - throw new SlcException("Key " + name + throw new SlcException("Key " + parameterName + " is not defined in the specifications of " + toString()); } } - throw new SlcException("Key " + name + " is not set as parameter in " + throw new SlcException("Key " + parameterName + " is not set as parameter in " + toString()); } @@ -165,4 +160,19 @@ public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean, return path; } + public void setPath(String path) { + this.path = path; + } + + public void setRegistry(StructureRegistry registry) { + this.registry = registry; + } + + public void notifyCurrentPath(StructureRegistry registry, + TreeSPath path) { + if (this.path == null) { + this.path = path.toString(); + } + } + }