]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionModuleDescriptor.java
Start new SLC project structure
[gpl/argeo-slc.git] / runtime / org.argeo.slc.specs / src / main / java / org / argeo / slc / execution / ExecutionModuleDescriptor.java
index 24aa5629d9b7fec3d639334a3361d6a7a8bf823b..4de0268228c8d1cc6305186dba92effb076613ab 100644 (file)
@@ -17,7 +17,9 @@ package org.argeo.slc.execution;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
+import org.argeo.slc.SlcException;
 import org.argeo.slc.deploy.ModuleDescriptor;
 
 /** Describes the information required to launch a flow */
@@ -37,6 +39,36 @@ public class ExecutionModuleDescriptor extends ModuleDescriptor {
                return executionFlows;
        }
 
+       /**
+        * Returns a new {@link ExecutionModuleDescriptor} that can be used to build
+        * a {@link RealizedFlow}.
+        */
+       public ExecutionFlowDescriptor cloneFlowDescriptor(String name) {
+               ExecutionFlowDescriptor res = null;
+               for (ExecutionFlowDescriptor efd : executionFlows) {
+                       if (efd.getName().equals(name)
+                                       || ("/" + efd.getName()).equals(name)) {
+                               try {
+                                       res = (ExecutionFlowDescriptor) efd.clone();
+                               } catch (CloneNotSupportedException e) {
+                                       throw new SlcException("Cannot clone " + efd, e);
+                               }
+                       }
+               }
+               if (res == null)
+                       throw new SlcException("Flow " + name + " not found.");
+               return res;
+       }
+
+       public RealizedFlow asRealizedFlow(String flow, Map<String, Object> values) {
+               RealizedFlow realizedFlow = new RealizedFlow();
+               realizedFlow.setFlowDescriptor(cloneFlowDescriptor(flow));
+               realizedFlow.setModuleName(getName());
+               realizedFlow.setModuleVersion(getVersion());
+               realizedFlow.getFlowDescriptor().getValues().putAll(values);
+               return realizedFlow;
+       }
+
        public void setExecutionSpecs(List<ExecutionSpec> executionSpecs) {
                this.executionSpecs = executionSpecs;
        }