/*
- * 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.
/*
* 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
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(
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()) {
// 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("")) {
// 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
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));