feat(import): deferred import connections

This commit is contained in:
Nico Rehwaldt 2014-07-23 18:53:04 +02:00
parent 816396139f
commit ec83cc67d9
2 changed files with 43 additions and 34 deletions

View File

@ -12,6 +12,10 @@ function BpmnTreeWalker(handler) {
// list of containers already walked
var handledProcesses = [];
// list of elements to handle deferred to ensure
// prerequisites are drawn
var deferred = [];
///// Helpers /////////////////////////////////
function contextual(fn, ctx) {
@ -42,9 +46,13 @@ function BpmnTreeWalker(handler) {
}
function visitIfDi(element, ctx) {
try {
if (element.di) {
return visit(element, ctx);
}
} catch (e) {
logError(e.message, { element: element, error: e });
}
}
function logError(message, context) {
@ -122,6 +130,13 @@ function BpmnTreeWalker(handler) {
} else {
throw new Error('unsupported root element for bpmndi:Diagram <' + rootElement.$type + '>');
}
// handle all deferred elements
handleDeferred(deferred);
}
function handleDeferred(deferred) {
_.forEach(deferred, function(d) { d(); });
}
function handleProcess(process, context) {
@ -202,13 +217,6 @@ function BpmnTreeWalker(handler) {
if (is(flowNode, 'bpmn:SubProcess')) {
handleSubProcess(flowNode, childCtx || context);
}
if (is(flowNode, 'bpmn:Activity')) {
_.forEach(flowNode.dataInputAssociations, contextual(handleDataAssociation, null));
_.forEach(flowNode.dataOutputAssociations, contextual(handleDataAssociation, null));
handleIoSpecification(flowNode.ioSpecification, context);
}
}
function handleSequenceFlow(sequenceFlow, context) {
@ -219,7 +227,7 @@ function BpmnTreeWalker(handler) {
visitIfDi(dataObject, context);
}
function handleBoundaryElement(dataObject, context) {
function handleBoundaryEvent(dataObject, context) {
visitIfDi(dataObject, context);
}
@ -255,41 +263,48 @@ function BpmnTreeWalker(handler) {
}
function handleNonFlowNodes(flowElements, context) {
var sequenceFlows = [];
var boundaryEvents = [];
_.forEach(flowElements, function(e) {
if (is(e, 'bpmn:SequenceFlow')) {
sequenceFlows.push(e);
deferred.push(function() {
handleSequenceFlow(e, context);
});
} else if (is(e, 'bpmn:BoundaryEvent')) {
deferred.unshift(function() {
handleBoundaryEvent(e, context);
});
} else if (is(e, 'bpmn:DataObject')) {
// SKIP (assume correct referencing via DataObjectReference)
} else if (is(e, 'bpmn:DataStoreReference')) {
handleDataElement(e, context);
} else if (is(e, 'bpmn:DataObjectReference')) {
handleDataElement(e, context);
} else if (is(e, 'bpmn:BoundaryEvent')) {
boundaryEvents.push(e);
}
});
// handle boundary events
_.forEach(boundaryEvents, contextual(handleBoundaryElement, context));
// handle SequenceFlows
_.forEach(sequenceFlows, contextual(handleSequenceFlow, context));
}
function handleFlowElements(flowElements, context) {
var sequenceFlows = [];
var boundaryEvents = [];
_.forEach(flowElements, function(e) {
if (is(e, 'bpmn:SequenceFlow')) {
sequenceFlows.push(e);
deferred.push(function() {
handleSequenceFlow(e, context);
});
} else if (is(e, 'bpmn:BoundaryEvent')) {
boundaryEvents.push(e);
deferred.unshift(function() {
handleBoundaryEvent(e, context);
});
} else if (is(e, 'bpmn:FlowNode')) {
handleFlowNode(e, context);
if (is(e, 'bpmn:Activity')) {
handleIoSpecification(e.ioSpecification, context);
// defer handling of associations
deferred.push(function() {
_.forEach(e.dataInputAssociations, contextual(handleDataAssociation, context));
_.forEach(e.dataOutputAssociations, contextual(handleDataAssociation, context));
});
}
} else if (is(e, 'bpmn:DataObject')) {
// SKIP (assume correct referencing via DataObjectReference)
} else if (is(e, 'bpmn:DataStoreReference')) {
@ -302,12 +317,6 @@ function BpmnTreeWalker(handler) {
{ element: e, context: context });
}
});
// handle boundary events
_.forEach(boundaryEvents, contextual(handleBoundaryElement, context));
// handle SequenceFlows
_.forEach(sequenceFlows, contextual(handleSequenceFlow, context));
}
function handleParticipant(participant, context) {

View File

@ -112,8 +112,8 @@ describe('import - importer', function() {
{ type: 'add', semantic: 'SubProcess_1', di: '_BPMNShape_SubProcess_2', diagramElement: 'SubProcess_1' },
{ type: 'add', semantic: 'StartEvent_1', di: '_BPMNShape_StartEvent_2', diagramElement: 'StartEvent_1' },
{ type: 'add', semantic: 'Task_1', di: '_BPMNShape_Task_2', diagramElement: 'Task_1' },
{ type: 'add', semantic: 'SequenceFlow_1', di: 'BPMNEdge_SequenceFlow_1', diagramElement: 'SequenceFlow_1' },
{ type: 'add', semantic: 'EndEvent_1', di: '_BPMNShape_EndEvent_2', diagramElement: 'EndEvent_1' },
{ type: 'add', semantic: 'SequenceFlow_1', di: 'BPMNEdge_SequenceFlow_1', diagramElement: 'SequenceFlow_1' },
{ type: 'add', semantic: 'SequenceFlow_2', di: 'BPMNEdge_SequenceFlow_2', diagramElement: 'SequenceFlow_2' }
]);