Skip to content

Commit

Permalink
assign incoming and outgoing ids of ShapeBpmnElement from flows
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet committed Apr 21, 2023
1 parent 7b62b77 commit 6066c9f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/component/parser/json/converter/ProcessConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ export default class ProcessConverter {

deserialize(processes: string | TProcess | (string | TProcess)[]): void {
ensureIsArray(processes).forEach(process => this.parseProcess(process));

// Need to call this after all processes have been parsed, because to link a call activity to the elements of the called process, we have to parse all processes before.
ensureIsArray(processes).forEach(process => this.assignParentOfProcessElementsCalledByCallActivity(process.id));

this.assignIncomingAndOutgoingIdsFromFlows();
}

private assignParentOfProcessElementsCalledByCallActivity(processId: string): void {
Expand All @@ -87,6 +90,24 @@ export default class ProcessConverter {
}
}

private assignIncomingAndOutgoingIdsFromFlows(): void {
const getShapeBpmnElement = (id: string): ShapeBpmnElement =>
this.convertedElements.findFlowNode(id) ?? this.convertedElements.findLane(id) ?? this.convertedElements.findPoolById(id);

const flows = [...this.convertedElements.getMessageFlows(), ...this.convertedElements.getSequenceFlows(), ...this.convertedElements.getAssociationFlows()];
flows.forEach(flow => {
const sourceElement = getShapeBpmnElement(flow.sourceRefId);
if (sourceElement && !sourceElement.outgoingIds.includes(flow.id)) {
sourceElement.outgoingIds.push(flow.id);
}

const targetElement = getShapeBpmnElement(flow.sourceRefId);
if (targetElement && !targetElement.incomingIds.includes(flow.id)) {
targetElement.incomingIds.push(flow.id);
}
});
}

private parseProcess(process: TProcess): void {
const processRef = process.id;
const pool = this.convertedElements.findPoolByProcessRef(processRef);
Expand All @@ -106,7 +127,7 @@ export default class ProcessConverter {
ShapeUtil.flowNodeKinds()
.filter(kind => kind != ShapeBpmnElementKind.EVENT_BOUNDARY)
.forEach(kind => this.buildFlowNodeBpmnElements(process[kind], kind, parentId, process.id));
// process boundary events afterwards as we need its parent activity to be available when building it
// process boundary events afterward as we need its parent activity to be available when building it
this.buildFlowNodeBpmnElements(process.boundaryEvent, ShapeBpmnElementKind.EVENT_BOUNDARY, parentId, process.id);

// containers
Expand Down
9 changes: 9 additions & 0 deletions src/component/parser/json/converter/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export class ConvertedElements {
findMessageFlow(id: string): MessageFlow {
return this.messageFlows.get(id);
}
getMessageFlows(): MessageFlow[] {
return Array.from(this.messageFlows.values());
}
registerMessageFlow(messageFlow: MessageFlow): void {
this.messageFlows.set(messageFlow.id, messageFlow);
}
Expand All @@ -69,6 +72,9 @@ export class ConvertedElements {
findSequenceFlow(id: string): SequenceFlow {
return this.sequenceFlows.get(id);
}
getSequenceFlows(): SequenceFlow[] {
return Array.from(this.sequenceFlows.values());
}
registerSequenceFlow(sequenceFlow: SequenceFlow): void {
this.sequenceFlows.set(sequenceFlow.id, sequenceFlow);
}
Expand All @@ -77,6 +83,9 @@ export class ConvertedElements {
findAssociationFlow(id: string): AssociationFlow {
return this.associationFlows.get(id);
}
getAssociationFlows(): AssociationFlow[] {
return Array.from(this.associationFlows.values());
}
registerAssociationFlow(associationFlow: AssociationFlow): void {
this.associationFlows.set(associationFlow.id, associationFlow);
}
Expand Down

0 comments on commit 6066c9f

Please sign in to comment.