]> 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
Work in progress - work on modular distributions.
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.jcr / src / main / java / org / argeo / slc / jcr / execution / JcrExecutionModulesListener.java
index 8d6d96784ab64562ea0e2e78b3647d01c9188b3e..ea734a8bbd6da7eed8c427b5321b7e74af6e5832 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2012 Mathieu Baudier
+ * Copyright (C) 2007-2012 Argeo GmbH
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -163,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
@@ -179,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(
@@ -239,8 +243,9 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                        String relativePath, ExecutionFlowDescriptor efd)
                        throws RepositoryException {
                Node flowNode = null;
-               Iterator<String> names = Arrays.asList(relativePath.split("/"))
-                               .iterator();
+               List<String> pathTokens = Arrays.asList(relativePath.split("/"));
+
+               Iterator<String> names = pathTokens.iterator();
                // create intermediary paths
                Node currNode = moduleNode;
                while (names.hasNext()) {
@@ -258,8 +263,7 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
 
                // name, description
                flowNode.setProperty(SLC_NAME, efd.getName());
-               String[] tokens = relativePath.split("/");
-               String endName = tokens[tokens.length - 1];
+               String endName = pathTokens.get(pathTokens.size() - 1);
                flowNode.setProperty(Property.JCR_TITLE, endName);
                if (efd.getDescription() != null
                                && !efd.getDescription().trim().equals("")) {
@@ -271,7 +275,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
@@ -286,18 +294,16 @@ public class JcrExecutionModulesListener implements ExecutionModulesListener,
                                                executionSpec.getDescription());
                        mapExecutionSpec(executionSpecNode, executionSpec);
                        flowNode.setProperty(SLC_SPEC, executionSpecNode);
-               } else {
-                       // internal spec node
-                       mapExecutionSpec(flowNode, executionSpec);
                }
 
-               // values
+               // flow 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);
+                               // if spec reference there will be no node at this stage
+                               Node valueNode = JcrUtils.getOrAdd(flowNode, attr);
                                valueNode.setProperty(SLC_TYPE, psa.getType());
                                SlcJcrUtils.setPrimitiveAsProperty(valueNode, SLC_VALUE,
                                                (PrimitiveValue) efd.getValues().get(attr));