Skip to content

Commit

Permalink
REfactor assignIncomingAndOutgoingIdsFromFlows function
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet committed Apr 24, 2023
1 parent 0ca259b commit f633cef
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/component/parser/json/converter/ProcessConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
ShapeUtil,
} from '../../../../model/bpmn/internal';
import { eventDefinitionKinds } from '../../../../model/bpmn/internal/shape/utils';
import type { MessageFlow, Flow } from '../../../../model/bpmn/internal/edge/flows';
import { AssociationFlow, SequenceFlow } from '../../../../model/bpmn/internal/edge/flows';
import type { TProcess } from '../../../../model/bpmn/json/baseElement/rootElement/rootElement';
import type { TBoundaryEvent, TCatchEvent, TThrowEvent } from '../../../../model/bpmn/json/baseElement/flowNode/event';
Expand Down Expand Up @@ -91,20 +92,22 @@ 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 fillShapeBpmnElementAttribute = (
shapeBpmnElementId: string,
shapeBpmnElementAttributeName: keyof Pick<ShapeBpmnElement, 'outgoingIds' | 'incomingIds'>,
valueToAdd: string,
): void => {
const shapeBpmnElement =
this.convertedElements.findFlowNode(shapeBpmnElementId) ?? this.convertedElements.findLane(shapeBpmnElementId) ?? this.convertedElements.findPoolById(shapeBpmnElementId);
if (shapeBpmnElement && !shapeBpmnElement[shapeBpmnElementAttributeName].includes(valueToAdd)) {
shapeBpmnElement[shapeBpmnElementAttributeName].push(valueToAdd);
}
};

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.targetRefId);
if (targetElement && !targetElement.incomingIds.includes(flow.id)) {
targetElement.incomingIds.push(flow.id);
}
fillShapeBpmnElementAttribute(flow.sourceRefId, 'outgoingIds', flow.id);
fillShapeBpmnElementAttribute(flow.targetRefId, 'incomingIds', flow.id);
});
}

Expand Down

0 comments on commit f633cef

Please sign in to comment.