+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.argeo.slc.jcr.execution;
import java.util.Arrays;
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;
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();
}
/*
* 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
for (String attr : efd.getValues().keySet()) {
ExecutionSpecAttribute esa = executionSpec.getAttributes()
.get(attr);
+ if (!flowNode.hasNode(attr))
+ throw new SlcException("No spec node for attribute '" + attr
+ + "' in flow " + flowNode.getPath());
if (esa instanceof PrimitiveSpecAttribute) {
PrimitiveSpecAttribute psa = (PrimitiveSpecAttribute) esa;
- Node valueNode = flowNode.addNode(attr);
+ Node valueNode = flowNode.getNode(attr);
valueNode.setProperty(SLC_TYPE, psa.getType());
SlcJcrUtils.setPrimitiveAsProperty(valueNode, SLC_VALUE,
(PrimitiveValue) efd.getValues().get(attr));
attrNode.addMixin(SlcTypes.SLC_REF_SPEC_ATTRIBUTE);
RefSpecAttribute rsa = (RefSpecAttribute) esa;
attrNode.setProperty(SLC_TYPE, rsa.getTargetClassName());
+ Object value = rsa.getValue();
if (rsa.getChoices() != null) {
+ Integer index = null;
+ int count = 0;
for (RefValueChoice choice : rsa.getChoices()) {
+ String name = choice.getName();
+ if (value != null && name.equals(value.toString()))
+ index = count;
Node choiceNode = attrNode.addNode(choice.getName());
choiceNode.addMixin(NodeType.MIX_TITLE);
choiceNode.setProperty(Property.JCR_TITLE,
&& !choice.getDescription().trim().equals(""))
choiceNode.setProperty(Property.JCR_DESCRIPTION,
choice.getDescription());
+ count++;
}
+
+ if (index != null)
+ attrNode.setProperty(SLC_VALUE, index);
}
}
}
Node moduleNode = agentNode.getNode(SlcJcrUtils
.getModuleNodeName(module));
String relativePath = getExecutionFlowRelativePath(executionFlow);
- if (!moduleNode.hasNode(relativePath))
+ if (moduleNode.hasNode(relativePath))
moduleNode.getNode(relativePath).remove();
agentNode.getSession().save();
} catch (RepositoryException e) {