UNPKG

@5minds/processcube_engine

Version:

The ProcessCube Engine. Stores and executes BPMNs.

76 lines 4.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.initialize = initialize; exports.getMessageEvents = getMessageEvents; exports.getSignalEvents = getSignalEvents; exports.getEventViewModels = getEventViewModels; const processcube_engine_sdk_1 = require("@5minds/processcube_engine_sdk"); const IocRegistrations_1 = require("../../Contracts/IocRegistrations"); const MonitoringManager_1 = require("..//MonitoringManager"); let container; function initialize(iocContainer) { container = iocContainer; } async function getMessageEvents(processModelIds, identity) { return (await getEventViewModels(processModelIds, identity)).filter((event) => event.messageName && event.messageName.length > 0); } async function getSignalEvents(processModelIds, identity) { return (await getEventViewModels(processModelIds, identity)).filter((event) => event.signalName && event.signalName.length > 0); } async function getEventViewModels(processModelIds, identity) { const functionReporter = MonitoringManager_1.MonitoringManager.getNewFunctionReporter('MonitoringManager.getProcessesWithEventDefinitions', { processModelIds, }); const processModelIdsToUse = typeof processModelIds === 'string' ? [processModelIds] : processModelIds; const processDefinitionMediator = container.get(IocRegistrations_1.IocRegistrationKeys.internal.ProcessDefinitionMediator); const identityToUse = identity ?? getInternalIdentity(); const runningDefinitions = await processDefinitionMediator.getDefinitionsWithRunningInstances(identityToUse, processModelIds); const deployedDefinitions = await processDefinitionMediator.getAll(identityToUse); const deployedEvents = deployedDefinitions .flatMap((definition) => definition.processes) .filter((processModel) => !processModelIdsToUse || processModelIdsToUse.length === 0 || processModelIdsToUse.includes(processModel.id)) .flatMap(mapToEventViewModels); const runningEvents = runningDefinitions .flatMap((definition) => definition.processes) .filter((processModel) => !processModelIdsToUse || processModelIdsToUse.length === 0 || processModelIdsToUse.includes(processModel.id)) .flatMap(mapToEventViewModels) .filter((event) => event.flowNodeType !== processcube_engine_sdk_1.BpmnType.startEvent); functionReporter.finish(); const allEvents = [...deployedEvents, ...runningEvents].filter(distinctEventViewModel); return allEvents; } function mapToEventViewModels(processModel) { return processModel.flowNodes .filter((flowNode) => flowNode.bpmnType === processcube_engine_sdk_1.BpmnType.intermediateThrowEvent || flowNode.bpmnType === processcube_engine_sdk_1.BpmnType.intermediateCatchEvent || flowNode.bpmnType === processcube_engine_sdk_1.BpmnType.receiveTask || flowNode.bpmnType === processcube_engine_sdk_1.BpmnType.sendTask || flowNode.bpmnType === processcube_engine_sdk_1.BpmnType.boundaryEvent || flowNode.bpmnType === processcube_engine_sdk_1.BpmnType.endEvent || flowNode.bpmnType === processcube_engine_sdk_1.BpmnType.startEvent) .map((flowNode) => processcube_engine_sdk_1.FlowNodeViewModelFactory.getViewModel(flowNode, { processModelId: processModel.id, processModelName: processModel.name, })); } function distinctEventViewModel(value, index, self) { return self.findIndex((event) => fuzzyEqualsEventViewModel(event, value)) === index; } function fuzzyEqualsEventViewModel(first, second) { return (first.id === second.id && first.name === second.name && first.messageId === second.messageId && first.messageName === second.messageName && first.messageChannel === second.messageChannel && first.signalId === second.signalId && first.signalName === second.signalName && first.signalChannel === second.signalChannel && first.triggerValueInEventPayload === second.triggerValueInEventPayload && first.processModelId === second.processModelId && first.processModelName === second.processModelName); } function getInternalIdentity() { const identityService = container.get(IocRegistrations_1.IocRegistrationKeys.internal.IdentityService); return identityService.getInternalIdentity(); } //# sourceMappingURL=GetEvents.js.map