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
.PrimitiveValue
;
17 import org
.argeo
.slc
.core
.execution
.ProcessThread
;
18 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
19 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
20 import org
.argeo
.slc
.execution
.ExecutionSpecAttribute
;
21 import org
.argeo
.slc
.jcr
.SlcJcrUtils
;
22 import org
.argeo
.slc
.jcr
.SlcNames
;
23 import org
.argeo
.slc
.jcr
.SlcTypes
;
24 import org
.argeo
.slc
.process
.RealizedFlow
;
26 /** Where the actual execution takes place */
27 public class JcrProcessThread
extends ProcessThread
implements SlcNames
{
29 public JcrProcessThread(ExecutionModulesManager executionModulesManager
,
30 JcrExecutionProcess process
) {
31 super(executionModulesManager
, process
);
35 protected void process() {
37 Node realizedFlowNode
= getNode().getNode(SLC_FLOW
);
38 // we just manage one level for the time being
39 NodeIterator nit
= realizedFlowNode
.getNodes(SLC_FLOW
);
40 while (nit
.hasNext()) {
41 process(nit
.nextNode());
43 } catch (RepositoryException e
) {
44 throw new ArgeoException("Cannot process " + getNode(), e
);
48 /** Configure the realized flows */
49 protected void process(Node realizedFlowNode
) throws RepositoryException
{
50 if (realizedFlowNode
.hasNode(SLC_ADDRESS
)) {
51 String flowPath
= realizedFlowNode
.getNode(SLC_ADDRESS
)
52 .getProperty(Property
.JCR_PATH
).getString();
53 // TODO: convert to local path if remote
55 Node flowNode
= realizedFlowNode
.getSession().getNode(flowPath
);
56 String flowName
= flowNode
.getProperty(SLC_NAME
).getString();
58 String executionModuleName
= SlcJcrUtils
59 .flowExecutionModuleName(flowPath
);
60 String executionModuleVersion
= SlcJcrUtils
61 .flowExecutionModuleVersion(flowPath
);
63 RealizedFlow realizedFlow
= new RealizedFlow();
64 realizedFlow
.setModuleName(executionModuleName
);
65 realizedFlow
.setModuleVersion(executionModuleVersion
);
67 DefaultExecutionSpec executionSpec
= null;
68 if (flowNode
.hasProperty(SlcNames
.SLC_SPEC
)) {
69 Node executionSpecNode
= flowNode
.getProperty(SLC_SPEC
)
71 executionSpec
= new DefaultExecutionSpec();
72 executionSpec
.setBeanName(executionSpecNode
.getProperty(
73 SLC_NAME
).getString());
75 .setAttributes(readExecutionSpecAttributes(executionSpecNode
));
77 // TODO: will with original attr
78 Map
<String
, ExecutionSpecAttribute
> attrs
= readExecutionSpecAttributes(realizedFlowNode
);
79 Map
<String
, Object
> values
= new HashMap
<String
, Object
>();
80 for (String attrName
: attrs
.keySet()) {
81 ExecutionSpecAttribute attr
= attrs
.get(attrName
);
82 Object value
= attr
.getValue();
83 values
.put(attrName
,value
);
86 // if(executionSpec!=null)
87 // executionSpec.setAttributes(attrs);
88 ExecutionFlowDescriptor efd
= new ExecutionFlowDescriptor(flowName
,
89 values
, executionSpec
);
90 realizedFlow
.setFlowDescriptor(efd
);
92 execute(realizedFlow
, true);
96 protected Map
<String
, ExecutionSpecAttribute
> readExecutionSpecAttributes(
99 Map
<String
, ExecutionSpecAttribute
> attrs
= new HashMap
<String
, ExecutionSpecAttribute
>();
100 for (NodeIterator nit
= node
.getNodes(); nit
.hasNext();) {
101 Node specAttrNode
= nit
.nextNode();
103 .isNodeType(SlcTypes
.SLC_PRIMITIVE_SPEC_ATTRIBUTE
)) {
104 String type
= specAttrNode
.getProperty(SLC_TYPE
)
106 if (specAttrNode
.hasProperty(SLC_VALUE
)) {
107 String valueStr
= specAttrNode
.getProperty(SLC_VALUE
)
109 Object value
= PrimitiveUtils
.convert(type
, valueStr
);
110 PrimitiveSpecAttribute specAttr
= new PrimitiveSpecAttribute(
112 attrs
.put(specAttrNode
.getName(), specAttr
);
118 } catch (RepositoryException e
) {
119 throw new SlcException("Cannot read spec attributes from " + node
,
124 protected Node
getNode() {
125 return ((JcrExecutionProcess
) getProcess()).getNode();