]> 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
Remove flow path
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.jcr / src / main / java / org / argeo / slc / jcr / execution / JcrExecutionModulesListener.java
index d108e9dd5b3d6cb7bf3710bbc3681dd4bef0a018..541d366bf78b2b74fb27b3d422f77ccd4530a265 100644 (file)
@@ -29,7 +29,6 @@ import javax.jcr.nodetype.NodeType;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.argeo.jcr.ArgeoNames;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.core.execution.PrimitiveSpecAttribute;
@@ -38,6 +37,7 @@ import org.argeo.slc.core.execution.RefSpecAttribute;
 import org.argeo.slc.core.execution.RefValueChoice;
 import org.argeo.slc.deploy.ModuleDescriptor;
 import org.argeo.slc.execution.ExecutionFlowDescriptor;
+import org.argeo.slc.execution.ExecutionModuleDescriptor;
 import org.argeo.slc.execution.ExecutionModulesListener;
 import org.argeo.slc.execution.ExecutionModulesManager;
 import org.argeo.slc.execution.ExecutionSpec;
@@ -76,38 +76,62 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                        session = repository.login();
                        clearAgent();
                        if (modulesManager != null) {
+                               Node agentNode = session.getNode(agent.getNodePath());
+
                                List<ModuleDescriptor> moduleDescriptors = modulesManager
                                                .listModules();
+
+                               // scan SLC-ExecutionModule metadata
+                               for (ModuleDescriptor md : moduleDescriptors) {
+                                       if (md.getMetadata().containsKey(
+                                                       ExecutionModuleDescriptor.SLC_EXECUTION_MODULE)) {
+                                               String moduleNodeName = SlcJcrUtils
+                                                               .getModuleNodeName(md);
+                                               Node moduleNode = agentNode.hasNode(moduleNodeName) ? agentNode
+                                                               .getNode(moduleNodeName) : agentNode
+                                                               .addNode(moduleNodeName);
+                                               moduleNode.addMixin(SlcTypes.SLC_EXECUTION_MODULE);
+                                               moduleNode.setProperty(SLC_NAME, md.getName());
+                                               moduleNode.setProperty(SLC_VERSION, md.getVersion());
+                                               moduleNode.setProperty(Property.JCR_TITLE,
+                                                               md.getTitle());
+                                               moduleNode.setProperty(Property.JCR_DESCRIPTION,
+                                                               md.getDescription());
+                                               moduleNode.setProperty(SLC_STARTED, md.getStarted());
+                                       }
+                               }
+
+                               // scan execution modules property
                                String executionModules = System
                                                .getProperty(SLC_EXECUTION_MODULES_PROPERTY);
                                if (executionModules != null) {
-                                       Node agentNode = session.getNode(agent.getNodePath());
                                        for (String executionModule : executionModules.split(",")) {
-                                               allModules: for (ModuleDescriptor moduleDescriptor : moduleDescriptors) {
+                                               allModules: for (ModuleDescriptor md : moduleDescriptors) {
                                                        String moduleNodeName = SlcJcrUtils
-                                                                       .getModuleNodeName(moduleDescriptor);
-                                                       if (moduleDescriptor.getName().equals(
-                                                                       executionModule)) {
+                                                                       .getModuleNodeName(md);
+                                                       if (md.getName().equals(executionModule)) {
                                                                Node moduleNode = agentNode
                                                                                .hasNode(moduleNodeName) ? agentNode
                                                                                .getNode(moduleNodeName) : agentNode
                                                                                .addNode(moduleNodeName);
                                                                moduleNode
                                                                                .addMixin(SlcTypes.SLC_EXECUTION_MODULE);
-                                                               moduleNode.setProperty(SLC_NAME,
-                                                                               moduleDescriptor.getName());
+                                                               moduleNode.setProperty(SLC_NAME, md.getName());
                                                                moduleNode.setProperty(SLC_VERSION,
-                                                                               moduleDescriptor.getVersion());
+                                                                               md.getVersion());
                                                                moduleNode.setProperty(Property.JCR_TITLE,
-                                                                               moduleDescriptor.getTitle());
+                                                                               md.getTitle());
                                                                moduleNode.setProperty(
                                                                                Property.JCR_DESCRIPTION,
-                                                                               moduleDescriptor.getDescription());
-                                                               moduleNode.setProperty(SLC_STARTED, false);
+                                                                               md.getDescription());
+                                                               moduleNode.setProperty(SLC_STARTED,
+                                                                               md.getStarted());
                                                                break allModules;
                                                        }
                                                }
                                        }
+
+                                       // save if needed
                                        if (session.hasPendingChanges())
                                                session.save();
                                }
@@ -139,8 +163,13 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
        /*
         * EXECUTION MODULES LISTENER
         */
+
        public synchronized void executionModuleAdded(
                        ModuleDescriptor moduleDescriptor) {
+               syncExecutionModule(moduleDescriptor);
+       }
+
+       protected void syncExecutionModule(ModuleDescriptor moduleDescriptor) {
                try {
                        Node agentNode = session.getNode(agent.getNodePath());
                        String moduleNodeName = SlcJcrUtils
@@ -155,13 +184,12 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                                        moduleDescriptor.getTitle());
                        moduleNode.setProperty(Property.JCR_DESCRIPTION,
                                        moduleDescriptor.getDescription());
-                       moduleNode.setProperty(SLC_STARTED, true);
+                       moduleNode.setProperty(SLC_STARTED, moduleDescriptor.getStarted());
                        session.save();
                } catch (RepositoryException e) {
                        JcrUtils.discardQuietly(session);
-                       throw new SlcException("Cannot add module " + moduleDescriptor, e);
+                       throw new SlcException("Cannot sync module " + moduleDescriptor, e);
                }
-
        }
 
        public synchronized void executionModuleRemoved(
@@ -215,6 +243,11 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                        String relativePath, ExecutionFlowDescriptor efd)
                        throws RepositoryException {
                Node flowNode = null;
+               // if (relativePath.startsWith("/"))
+               // relativePath = relativePath.substring(1);
+               // if (relativePath.endsWith("/"))
+               // relativePath = relativePath.substring(0, relativePath.length() - 1);
+
                Iterator<String> names = Arrays.asList(relativePath.split("/"))
                                .iterator();
                // create intermediary paths
@@ -247,7 +280,11 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                // execution spec
                ExecutionSpec executionSpec = efd.getExecutionSpec();
                String esName = executionSpec.getName();
-               if (!(esName == null || esName.equals(ExecutionSpec.INTERNAL_NAME))) {
+               if (esName == null || esName.equals(ExecutionSpec.INTERNAL_NAME)
+                               || esName.contains("#")/* automatically generated bean name */) {
+                       // internal spec node
+                       mapExecutionSpec(flowNode, executionSpec);
+               } else {
                        // reference spec node
                        Node executionSpecsNode = moduleNode.hasNode(SLC_EXECUTION_SPECS) ? moduleNode
                                        .getNode(SLC_EXECUTION_SPECS) : moduleNode
@@ -262,9 +299,6 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                                                executionSpec.getDescription());
                        mapExecutionSpec(executionSpecNode, executionSpec);
                        flowNode.setProperty(SLC_SPEC, executionSpecNode);
-               } else {
-                       // internal spec node
-                       mapExecutionSpec(flowNode, executionSpec);
                }
 
                // values
@@ -354,12 +388,9 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
         * UTILITIES
         */
        /** @return the relative path, never starts with '/' */
-       @SuppressWarnings("deprecation")
        protected String getExecutionFlowRelativePath(
                        ExecutionFlowDescriptor executionFlow) {
-               String relativePath = executionFlow.getPath() == null ? executionFlow
-                               .getName() : executionFlow.getPath() + '/'
-                               + executionFlow.getName();
+               String relativePath = executionFlow.getName();
                // we assume that it is more than one char long
                if (relativePath.charAt(0) == '/')
                        relativePath = relativePath.substring(1);