import java.util.Arrays;
import java.util.Iterator;
+import java.util.List;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.SlcException;
import org.argeo.slc.core.execution.PrimitiveSpecAttribute;
+import org.argeo.slc.core.execution.PrimitiveValue;
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.ExecutionModulesListener;
+import org.argeo.slc.execution.ExecutionModulesManager;
import org.argeo.slc.execution.ExecutionSpec;
import org.argeo.slc.execution.ExecutionSpecAttribute;
import org.argeo.slc.jcr.SlcJcrUtils;
*/
public class JcrExecutionModulesListener implements ExecutionModulesListener,
SlcNames {
+ private final static String SLC_EXECUTION_MODRULES_PROPERTY = "slc.executionModules";
+
private final static Log log = LogFactory
.getLog(JcrExecutionModulesListener.class);
private JcrAgent agent;
+ private ExecutionModulesManager modulesManager;
+
/**
* We don't use a thread bound session because many different threads will
* call this critical component and we don't want to login each time. We
*/
public void init() {
clearAgent();
+ if (modulesManager != null) {
+ List<ModuleDescriptor> moduleDescriptors = modulesManager
+ .listModules();
+ String executionModules = System
+ .getProperty(SLC_EXECUTION_MODRULES_PROPERTY);
+ if (executionModules != null)
+ try {
+ Node agentNode = session.getNode(agent.getNodePath());
+ for (String executionModule : executionModules.split(",")) {
+ for (ModuleDescriptor moduleDescriptor : moduleDescriptors) {
+ String moduleNodeName = SlcJcrUtils
+ .getModuleNodeName(moduleDescriptor);
+ if (moduleDescriptor.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_VERSION,
+ moduleDescriptor.getVersion());
+ moduleNode.setProperty(Property.JCR_TITLE,
+ moduleDescriptor.getTitle());
+ moduleNode.setProperty(
+ Property.JCR_DESCRIPTION,
+ moduleDescriptor.getDescription());
+ moduleNode.setProperty(SLC_STARTED, false);
+ }
+ }
+ }
+ session.save();
+ } catch (RepositoryException e) {
+ JcrUtils.discardQuietly(session);
+ throw new SlcException("Cannot initialize modules", e);
+ }
+ }
}
public void dispose() {
moduleDescriptor.getTitle());
moduleNode.setProperty(Property.JCR_DESCRIPTION,
moduleDescriptor.getDescription());
+ moduleNode.setProperty(SLC_STARTED, true);
session.save();
} catch (RepositoryException e) {
JcrUtils.discardQuietly(session);
try {
String moduleName = SlcJcrUtils.getModuleNodeName(moduleDescriptor);
Node agentNode = session.getNode(agent.getNodePath());
- if (agentNode.hasNode(moduleName))
- agentNode.getNode(moduleName).remove();
- agentNode.getSession().save();
+ if (agentNode.hasNode(moduleName)) {
+ Node moduleNode = agentNode.getNode(moduleName);
+ for (NodeIterator nit = moduleNode.getNodes(); nit.hasNext();) {
+ nit.nextNode().remove();
+ }
+ moduleNode.setProperty(SLC_STARTED, false);
+ }
+ session.save();
} catch (RepositoryException e) {
+ JcrUtils.discardQuietly(session);
throw new SlcException("Cannot remove module " + moduleDescriptor,
e);
}
SlcTypes.SLC_EXECUTION_FLOW);
}
}
+
+ // name, description
flowNode.setProperty(SLC_NAME, efd.getName());
String[] tokens = relativePath.split("/");
flowNode.setProperty(Property.JCR_TITLE, tokens[tokens.length - 1]);
// 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))) {
+ // reference spec node
Node executionSpecsNode = moduleNode.hasNode(SLC_EXECUTION_SPECS) ? moduleNode
.getNode(SLC_EXECUTION_SPECS) : moduleNode
.addNode(SLC_EXECUTION_SPECS);
Node executionSpecNode = executionSpecsNode.addNode(esName,
SlcTypes.SLC_EXECUTION_SPEC);
+ executionSpecNode.setProperty(SLC_NAME, esName);
executionSpecNode.setProperty(Property.JCR_TITLE, esName);
if (executionSpec.getDescription() != null
&& !executionSpec.getDescription().trim().equals(""))
executionSpecNode.setProperty(Property.JCR_DESCRIPTION,
executionSpec.getDescription());
mapExecutionSpec(executionSpecNode, executionSpec);
+ flowNode.setProperty(SLC_SPEC, executionSpecNode);
} else {
+ // internal spec node
mapExecutionSpec(flowNode, executionSpec);
}
+
+ // values
+ for (String attr : efd.getValues().keySet()) {
+ if (log.isDebugEnabled())
+ log.debug(attr + "=" + efd.getValues().get(attr));
+ ExecutionSpecAttribute esa = executionSpec.getAttributes()
+ .get(attr);
+ if (esa instanceof PrimitiveSpecAttribute) {
+ PrimitiveSpecAttribute psa = (PrimitiveSpecAttribute) esa;
+ Node valueNode = flowNode.addNode(attr);
+ valueNode.setProperty(SLC_TYPE, psa.getType());
+ SlcJcrUtils.setPrimitiveAsProperty(valueNode, SLC_VALUE,
+ (PrimitiveValue) efd.getValues().get(attr));
+ }
+ }
+
return flowNode;
}
// we assume that it is more than one char long
if (relativePath.charAt(0) == '/')
relativePath = relativePath.substring(1);
+ // FIXME quick hack to avoid duplicate '/'
+ relativePath = relativePath.replaceAll("//", "/");
return relativePath;
}
this.session = session;
}
+ public void setModulesManager(ExecutionModulesManager modulesManager) {
+ this.modulesManager = modulesManager;
+ }
+
}