X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fjcr%2Fexecution%2FJcrExecutionModulesListener.java;h=ea734a8bbd6da7eed8c427b5321b7e74af6e5832;hb=2ecb1e7ce15a25ba8026b5ded625f36c1be467bd;hp=8d6d96784ab64562ea0e2e78b3647d01c9188b3e;hpb=699640c58cc0578beebfc3edd00dac9eed65ee0b;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java index 8d6d96784..ea734a8bb 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionModulesListener.java @@ -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 names = Arrays.asList(relativePath.split("/")) - .iterator(); + List pathTokens = Arrays.asList(relativePath.split("/")); + + Iterator 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));