- public void executionFlowAdded(Module module, ExecutionFlow executionFlow) {
- String path = getExecutionFlowPath(module, executionFlow);
- log.debug("path=" + path);
- try {
- Node flowNode;
- if (!session.nodeExists(path)) {
- Node base = session.getNode(modulesPath);
- Node moduleNode = base.getNode(module.getName() + '/'
- + module.getVersion());
- String relativePath = getExecutionFlowRelativePath(executionFlow);
- log.debug("relativePath='" + relativePath + "'");
- Iterator<String> names = Arrays.asList(relativePath.split("/"))
- .iterator();
- Node currNode = moduleNode;
- while (names.hasNext()) {
- String name = names.next();
- if (currNode.hasNode(name))
- currNode = currNode.getNode(name);
- else {
- if (names.hasNext())
- currNode = currNode.addNode(name);
- else
- flowNode = currNode.addNode(name);
+ protected Node createExecutionFlowNode(Node moduleNode,
+ String relativePath, ExecutionFlowDescriptor efd)
+ throws RepositoryException {
+ Node flowNode = null;
+ Iterator<String> names = Arrays.asList(relativePath.split("/"))
+ .iterator();
+ // create intermediary paths
+ Node currNode = moduleNode;
+ while (names.hasNext()) {
+ String name = names.next();
+ if (currNode.hasNode(name))
+ currNode = currNode.getNode(name);
+ else {
+ if (names.hasNext())
+ currNode = currNode.addNode(name);
+ else
+ flowNode = currNode.addNode(name,
+ SlcTypes.SLC_EXECUTION_FLOW);
+ }
+ }
+ flowNode.setProperty(SLC_NAME, efd.getName());
+ String[] tokens = relativePath.split("/");
+ flowNode.setProperty(Property.JCR_TITLE, tokens[tokens.length - 1]);
+ if (efd.getDescription() != null
+ && efd.getDescription().trim().equals(""))
+ flowNode.setProperty(Property.JCR_DESCRIPTION, efd.getDescription());
+
+ // execution spec
+ ExecutionSpec executionSpec = efd.getExecutionSpec();
+ String esName = executionSpec.getName();
+ if (!(esName == null || esName.equals(ExecutionSpec.INTERNAL_NAME))) {
+ 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 {
+ mapExecutionSpec(flowNode, executionSpec);
+ }
+ return flowNode;
+ }
+
+ /**
+ * Base can be either an execution spec node, or an execution flow node (in
+ * case the execution spec is internal)
+ */
+ protected void mapExecutionSpec(Node baseNode, ExecutionSpec executionSpec)
+ throws RepositoryException {
+ for (String attrName : executionSpec.getAttributes().keySet()) {
+ ExecutionSpecAttribute esa = executionSpec.getAttributes().get(
+ attrName);
+ Node attrNode = baseNode.addNode(attrName);
+ // booleans
+ attrNode.addMixin(SlcTypes.SLC_EXECUTION_SPEC_ATTRIBUTE);
+ attrNode.setProperty(SLC_IS_IMMUTABLE, esa.getIsImmutable());
+ attrNode.setProperty(SLC_IS_CONSTANT, esa.getIsConstant());
+ attrNode.setProperty(SLC_IS_HIDDEN, esa.getIsHidden());
+
+ if (esa instanceof PrimitiveSpecAttribute) {
+ attrNode.addMixin(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE);
+ PrimitiveSpecAttribute psa = (PrimitiveSpecAttribute) esa;
+ SlcJcrUtils.setPrimitiveAsProperty(attrNode, SLC_VALUE, psa);
+ attrNode.setProperty(SLC_TYPE, psa.getType());
+ } else if (esa instanceof RefSpecAttribute) {
+ attrNode.addMixin(SlcTypes.SLC_REF_SPEC_ATTRIBUTE);
+ RefSpecAttribute rsa = (RefSpecAttribute) esa;
+ attrNode.setProperty(SLC_TYPE, rsa.getTargetClassName());
+ if (rsa.getChoices() != null) {
+ for (RefValueChoice choice : rsa.getChoices()) {
+ Node choiceNode = attrNode.addNode(choice.getName());
+ choiceNode.addMixin(NodeType.MIX_TITLE);
+ choiceNode.setProperty(Property.JCR_TITLE,
+ choice.getName());
+ if (choice.getDescription() != null
+ && !choice.getDescription().trim().equals(""))
+ choiceNode.setProperty(Property.JCR_DESCRIPTION,
+ choice.getDescription());