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 2da3801
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/component/parser/json/converter/ProcessConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,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 2da3801

Please sign in to comment.