for (FlowNode flowNode : flowNodes) {
LOG.debug(String
.format("FlowNode to be instantiated: %s:%s", flowNode.getFlowNodeId(), flowNode.getNodeType()));
FlowNodeInstance flowNodeInstance = new FlowNodeInstance(
NodeInstaceStates.INACTIVE_STATE,
flowNode.getFiredFlowsNeeded());
flowNodeInstance.addAsInstanceOf(flowNode, processInstanceId);
flowNodeInstanceRepositoryService.save(flowNodeInstance);
flowNodeInstances.put(flowNode, flowNodeInstance);
}
// create relationships between the node instances
for (FlowNode flowNode : flowNodeInstances.keySet()) {
// get the flow node this instance node is an instance of (it has
// the needed relationship information)
FlowNodeInstance flowNodeInstance = flowNodeInstances.get(flowNode);
// mirror the flow node relationships to the flow node instances
for (FlowNode followingFlowNode : neo4jTemplate.fetch(flowNode.getFollowingFlowNodes())) {
// (TODO: evaluate if a query beginning at the process might be faster)
FlowNodeInstance followingFlowNodeInstance = flowNodeInstanceRepositoryService
.findFlowNodeInstance(followingFlowNode.getGraphId(),
processInstanceId);
flowNodeInstance.addFollowingInstance(followingFlowNodeInstance);