]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java
Save current state even if not completely stable
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.jcr / src / main / java / org / argeo / slc / jcr / execution / JcrExecutionModulesListener.java
index 90b86f3d327549e76cb2693726795d102532e6c7..044036c0eb4e7395f6131b323c3d1d56a0416eff 100644 (file)
@@ -16,6 +16,7 @@ import org.apache.commons.logging.LogFactory;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.core.execution.PrimitiveSpecAttribute;
+import org.argeo.slc.core.execution.PrimitiveValue;
 import org.argeo.slc.core.execution.RefSpecAttribute;
 import org.argeo.slc.core.execution.RefValueChoice;
 import org.argeo.slc.deploy.ModuleDescriptor;
@@ -34,7 +35,7 @@ import org.argeo.slc.jcr.SlcTypes;
  */
 public class JcrExecutionModulesListener implements ExecutionModulesListener,
                SlcNames {
-       private final static String SLC_EXECUTION_MODRULES_PROPERTY = "slc.executionModules";
+       private final static String SLC_EXECUTION_MODULES_PROPERTY = "slc.executionModules";
 
        private final static Log log = LogFactory
                        .getLog(JcrExecutionModulesListener.class);
@@ -58,7 +59,7 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                        List<ModuleDescriptor> moduleDescriptors = modulesManager
                                        .listModules();
                        String executionModules = System
-                                       .getProperty(SLC_EXECUTION_MODRULES_PROPERTY);
+                                       .getProperty(SLC_EXECUTION_MODULES_PROPERTY);
                        if (executionModules != null)
                                try {
                                        Node agentNode = session.getNode(agent.getNodePath());
@@ -207,17 +208,24 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                                                        SlcTypes.SLC_EXECUTION_FLOW);
                        }
                }
+
+               // name, description
                flowNode.setProperty(SLC_NAME, efd.getName());
                String[] tokens = relativePath.split("/");
-               flowNode.setProperty(Property.JCR_TITLE, tokens[tokens.length - 1]);
+               String endName = tokens[tokens.length - 1];
                if (efd.getDescription() != null
-                               && efd.getDescription().trim().equals(""))
-                       flowNode.setProperty(Property.JCR_DESCRIPTION, efd.getDescription());
+                               && !efd.getDescription().trim().equals("")) {
+                       flowNode.setProperty(Property.JCR_TITLE, efd.getDescription());
+               } else {
+                       flowNode.setProperty(Property.JCR_TITLE, endName);
+               }
+               flowNode.setProperty(Property.JCR_DESCRIPTION, endName);
 
                // execution spec
                ExecutionSpec executionSpec = efd.getExecutionSpec();
                String esName = executionSpec.getName();
                if (!(esName == null || esName.equals(ExecutionSpec.INTERNAL_NAME))) {
+                       // reference spec node
                        Node executionSpecsNode = moduleNode.hasNode(SLC_EXECUTION_SPECS) ? moduleNode
                                        .getNode(SLC_EXECUTION_SPECS) : moduleNode
                                        .addNode(SLC_EXECUTION_SPECS);
@@ -232,8 +240,23 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                        mapExecutionSpec(executionSpecNode, executionSpec);
                        flowNode.setProperty(SLC_SPEC, executionSpecNode);
                } else {
+                       // internal spec node
                        mapExecutionSpec(flowNode, executionSpec);
                }
+
+               // values
+               for (String attr : efd.getValues().keySet()) {
+                       ExecutionSpecAttribute esa = executionSpec.getAttributes()
+                                       .get(attr);
+                       if (esa instanceof PrimitiveSpecAttribute) {
+                               PrimitiveSpecAttribute psa = (PrimitiveSpecAttribute) esa;
+                               Node valueNode = flowNode.addNode(attr);
+                               valueNode.setProperty(SLC_TYPE, psa.getType());
+                               SlcJcrUtils.setPrimitiveAsProperty(valueNode, SLC_VALUE,
+                                               (PrimitiveValue) efd.getValues().get(attr));
+                       }
+               }
+
                return flowNode;
        }