1 package org
.argeo
.slc
.jcr
.execution
;
3 import java
.util
.HashMap
;
7 import javax
.jcr
.NodeIterator
;
8 import javax
.jcr
.Property
;
9 import javax
.jcr
.RepositoryException
;
11 import org
.argeo
.ArgeoException
;
12 import org
.argeo
.slc
.SlcException
;
13 import org
.argeo
.slc
.core
.execution
.DefaultExecutionSpec
;
14 import org
.argeo
.slc
.core
.execution
.PrimitiveSpecAttribute
;
15 import org
.argeo
.slc
.core
.execution
.PrimitiveUtils
;
16 import org
.argeo
.slc
.core
.execution
.ProcessThread
;
17 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
18 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
19 import org
.argeo
.slc
.execution
.ExecutionSpecAttribute
;
20 import org
.argeo
.slc
.jcr
.SlcJcrUtils
;
21 import org
.argeo
.slc
.jcr
.SlcNames
;
22 import org
.argeo
.slc
.jcr
.SlcTypes
;
23 import org
.argeo
.slc
.process
.RealizedFlow
;
25 /** Where the actual execution takes place */
26 public class JcrProcessThread
extends ProcessThread
implements SlcNames
{
28 public JcrProcessThread(ExecutionModulesManager executionModulesManager
,
29 JcrExecutionProcess process
) {
30 super(executionModulesManager
, process
);
34 protected void process() {
36 Node realizedFlowNode
= getNode().getNode(SLC_FLOW
);
37 // we just manage one level for the time being
38 NodeIterator nit
= realizedFlowNode
.getNodes(SLC_FLOW
);
39 while (nit
.hasNext()) {
40 process(nit
.nextNode());
42 } catch (RepositoryException e
) {
43 throw new ArgeoException("Cannot process " + getNode(), e
);
47 /** Configure the realized flows */
48 protected void process(Node realizedFlowNode
) throws RepositoryException
{
49 if (realizedFlowNode
.hasNode(SLC_ADDRESS
)) {
50 String flowPath
= realizedFlowNode
.getNode(SLC_ADDRESS
)
51 .getProperty(Property
.JCR_PATH
).getString();
52 // TODO: convert to local path if remote
54 Node flowNode
= realizedFlowNode
.getSession().getNode(flowPath
);
55 String flowName
= flowNode
.getProperty(SLC_NAME
).getString();
57 String executionModuleName
= SlcJcrUtils
58 .flowExecutionModuleName(flowPath
);
59 String executionModuleVersion
= SlcJcrUtils
60 .flowExecutionModuleVersion(flowPath
);
62 RealizedFlow realizedFlow
= new RealizedFlow();
63 realizedFlow
.setModuleName(executionModuleName
);
64 realizedFlow
.setModuleVersion(executionModuleVersion
);
66 DefaultExecutionSpec executionSpec
= null;
67 if (flowNode
.hasProperty(SlcNames
.SLC_SPEC
)) {
68 Node executionSpecNode
= flowNode
.getProperty(SLC_SPEC
)
70 executionSpec
= new DefaultExecutionSpec();
71 executionSpec
.setBeanName(executionSpecNode
.getProperty(
72 SLC_NAME
).getString());
74 .setAttributes(readExecutionSpecAttributes(executionSpecNode
));
76 // TODO: will with original attr
77 Map
<String
, ExecutionSpecAttribute
> attrs
= readExecutionSpecAttributes(realizedFlowNode
);
78 Map
<String
, Object
> values
= new HashMap
<String
, Object
>();
79 for (String attrName
: attrs
.keySet()) {
80 ExecutionSpecAttribute attr
= attrs
.get(attrName
);
81 Object value
= attr
.getValue();
82 values
.put(attrName
,value
);
85 // if(executionSpec!=null)
86 // executionSpec.setAttributes(attrs);
87 ExecutionFlowDescriptor efd
= new ExecutionFlowDescriptor(flowName
,
88 values
, executionSpec
);
89 realizedFlow
.setFlowDescriptor(efd
);
91 execute(realizedFlow
, true);
95 protected Map
<String
, ExecutionSpecAttribute
> readExecutionSpecAttributes(
98 Map
<String
, ExecutionSpecAttribute
> attrs
= new HashMap
<String
, ExecutionSpecAttribute
>();
99 for (NodeIterator nit
= node
.getNodes(); nit
.hasNext();) {
100 Node specAttrNode
= nit
.nextNode();
102 .isNodeType(SlcTypes
.SLC_PRIMITIVE_SPEC_ATTRIBUTE
)) {
103 String type
= specAttrNode
.getProperty(SLC_TYPE
)
105 if (specAttrNode
.hasProperty(SLC_VALUE
)) {
106 String valueStr
= specAttrNode
.getProperty(SLC_VALUE
)
108 Object value
= PrimitiveUtils
.convert(type
, valueStr
);
109 PrimitiveSpecAttribute specAttr
= new PrimitiveSpecAttribute(
111 attrs
.put(specAttrNode
.getName(), specAttr
);
117 } catch (RepositoryException e
) {
118 throw new SlcException("Cannot read spec attributes from " + node
,
123 protected Node
getNode() {
124 return ((JcrExecutionProcess
) getProcess()).getNode();