Skip to content

Commit 58711bc

Browse files
committed
[REFACTOR] ProcessConverter: simplify event definitions retrieval
Previously, for a given 'bpmn element', we retrieved a list with all event definitions that exist in the spec with the number of occurrences associated to the 'bpmn element'. It was not obvious that this list contained all definitions with some occurrence counters set to zero: - generally, the intuition of the reader is to have only definitions for non zero counts. - in addition, the method documentation confirmed this intuition 'Get the list of eventDefinition hold by the Event bpmElement'. It never talked about zero counters Second, this required an extra filtering to only get the definitions actually hold by the bpmn element (only keep definitions with non zero counter). The new implementation now returns only a list of event definitions with non zero counter i.e. the event definitions declared in the BPMN definition with their occurrence count. This method is in charge of the zero counter filtering, letting the client code cleaner.
1 parent ba04d67 commit 58711bc

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/component/parser/json/converter/ProcessConverter.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,29 @@ export default class ProcessConverter extends AbstractConverter<Process> {
118118
}
119119

120120
if (numberOfEventDefinitions == 1) {
121-
const eventDefinition = eventDefinitions.filter(eventDefinition => eventDefinition.counter == 1)[0];
121+
const eventDefinition = eventDefinitions[0];
122122
if (supportedBpmnEventKinds.includes(eventDefinition.kind)) {
123123
return new ShapeBpmnEvent(bpmnElement.id, bpmnElement.name, elementKind, eventDefinition.kind, processId);
124124
}
125125
}
126126
}
127127

128128
/**
129-
* Get the list of eventDefinition hold by the Event bpmElement
129+
* Get the list of eventDefinitions hold by the Event bpmElement
130130
*
131131
* @param bpmnElement The BPMN element from the XML data which represents a BPMN Event
132132
*/
133133
// eslint-disable-next-line @typescript-eslint/no-explicit-any
134134
private getEventDefinitions(bpmnElement: any): EventDefinition[] {
135-
return bpmnEventKinds.map(eventKind => {
136-
// sometimes eventDefinition is simple and therefore it is parsed as empty string "", in that case eventDefinition will be converted to an empty object
137-
const eventDefinition = bpmnElement[eventKind + 'EventDefinition'];
138-
return { kind: eventKind, counter: ensureIsArray(eventDefinition, true).length };
139-
});
135+
return bpmnEventKinds
136+
.map(eventKind => {
137+
// sometimes eventDefinition is simple and therefore it is parsed as empty string "", in that case eventDefinition will be converted to an empty object
138+
const eventDefinition = bpmnElement[eventKind + 'EventDefinition'];
139+
return { kind: eventKind, counter: ensureIsArray(eventDefinition, true).length };
140+
})
141+
.filter(eventDefinition => {
142+
return eventDefinition.counter > 0;
143+
});
140144
}
141145

142146
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)