UNPKG

@5minds/processcube_engine

Version:

The ProcessCube Engine. Stores and executes BPMNs.

106 lines 5.7 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EndEventHandler = void 0; const dayjs_1 = __importDefault(require("dayjs")); const inversify_1 = require("inversify"); const processcube_engine_sdk_1 = require("@5minds/processcube_engine_sdk"); const index_1 = require("../../../Contracts/index"); const EventAggregator_1 = __importDefault(require("../../../Tools/EventAggregator")); const index_2 = require("../../../Tools/index"); const ProcessInstance_1 = require("../../ProcessInstance"); const FlowNodeHandlerFactory_1 = require("../FlowNodeHandlerFactory"); const EventHandler_1 = require("./EventHandler"); let EndEventHandler = class EndEventHandler extends EventHandler_1.EventHandler { eventName; customCorrelationId; constructor(eventMiddlewareHandler, flowNodeHandlerFactory, flowNodeInstanceDatabaseAdapter, endEventModel, processInstance, namespace) { super(eventMiddlewareHandler, flowNodeHandlerFactory, flowNodeInstanceDatabaseAdapter, endEventModel, processInstance, namespace ?? 'end_event_handler'); } get endEvent() { return this.flowNode; } // Overriding this hook here prevents it from creating subscriptions for // termination, error and kill events, which we neither need nor want for EndEvents. async beforeExecute() { this.subscribeToMiddlewareEvent(); } async persistOnCancel(typeData) { await super.persistOnCancel(typeData); this.publishEndEventFinishedNotification(); } async persistOnExit(typeData) { await super.persistOnExit(typeData); this.publishEndEventFinishedNotification(); } async persistOnError(error, typeData) { await super.persistOnError(error, typeData); this.publishEndEventFinishedNotification(); } async persistOnTerminate(typeData) { await super.persistOnTerminate(typeData); this.publishEndEventFinishedNotification(); } async startExecution() { this.logger.debug(`Executing EndEvent instance.`); return this.executeHandler(); } async executeHandler() { return undefined; } async publishEndEventFinishedNotification() { const message = { correlationId: this.processInstance.getCorrelationId(), processDefinitionId: this.processInstance.getProcessDefinitionId(), processModelId: this.processInstance.getProcessModelId(), embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(), processModelName: this.processInstance.getProcessModelName(), processInstanceId: this.processInstance.getProcessInstanceId(), parentProcessInstanceId: this.processInstance.getParentProcessInstance()?.getProcessInstanceId(), flowNodeId: this.endEvent.id, flowNodeName: this.endEvent.name, flowNodeType: this.endEvent.bpmnType, flowNodeLane: this.processInstance.getProcessModelFacade().getLaneForFlowNode(this.endEvent.id)?.name, flowNodeInstanceId: this.flowNodeInstanceId, logLevel: processcube_engine_sdk_1.LogLevel.debug, timestamp: dayjs_1.default.utc().toDate(), processDefinitionHash: this.processInstance.getProcessDefinitionHash(), processInstanceOwner: this.processInstance.getOwner(), currentToken: this.processToken, previousFlowNodeInstanceId: this.previousFlowNodeInstanceId, eventType: processcube_engine_sdk_1.EngineEventType.OnFlowNodeExited, eventName: this.endEvent.signalEventDefinition?.name ?? this.endEvent.messageEventDefinition?.name, endEventType: this.endEvent.eventType, }; EventAggregator_1.default.publish(index_1.eventAggregatorSettings.messagePaths.endEventFinished, message); } async executeExpression(expression, allowNonObjectResults = false, dataContract) { return this.processInstance.executeRuntimeExpression({ expression: expression, currentFlowNode: this.endEvent, currentToken: this.processToken, previousFlowNode: this.processInstance.getProcessModelFacade().getPreviousFlowNodesFor(this.endEvent)?.pop(), allowNonObjectResults: allowNonObjectResults, dataContract: dataContract, }); } }; exports.EndEventHandler = EndEventHandler; exports.EndEventHandler = EndEventHandler = __decorate([ (0, inversify_1.injectable)(), __metadata("design:paramtypes", [index_2.EventMiddlewareHandler, FlowNodeHandlerFactory_1.FlowNodeHandlerFactory, index_2.FlowNodeInstanceDatabaseAdapter, Object, ProcessInstance_1.ProcessInstance, String]) ], EndEventHandler); //# sourceMappingURL=EndEventHandler.js.map