UNPKG

@5minds/processcube_engine

Version:

The ProcessCube Engine. Stores and executes BPMNs.

97 lines 5.51 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EndEscalationEventHandler = void 0; const inversify_1 = require("inversify"); const processcube_engine_sdk_1 = require("@5minds/processcube_engine_sdk"); const index_1 = require("../../../Contracts/index"); const index_2 = require("../../../Tools/index"); const EscalationEventService_1 = require("../../EscalationEventService"); const ProcessInstance_1 = require("../../ProcessInstance"); const FlowNodeHandlerFactory_1 = require("../FlowNodeHandlerFactory"); const EndEventHandler_1 = require("./EndEventHandler"); let EndEscalationEventHandler = class EndEscalationEventHandler extends EndEventHandler_1.EndEventHandler { escalationEventService; constructor(eventMiddlewareHandler, flowNodeHandlerFactory, flowNodeInstanceDatabaseAdapter, escalationEndEventModel, processInstance, escalationEventService) { super(eventMiddlewareHandler, flowNodeHandlerFactory, flowNodeInstanceDatabaseAdapter, escalationEndEventModel, processInstance, 'escalation_end_event_handler'); this.escalationEventService = escalationEventService; } get escalationEndEvent() { return this.endEvent; } async persistOnExit() { await super.persistOnExit({ type: index_1.FlowNodeInstanceDataTypes.throwEvent, eventName: this.escalationEndEvent.escalationEventDefinition?.name, }); } async startExecution() { this.logger.debug(`Executing escalationEndEvent instance.`); return this.executeHandler(); } async executeHandler() { return new Promise(async (resolve, reject) => { try { this.ensureHasClaim(); if (!this.escalationEndEvent.escalationEventDefinition?.escalationCode) { throw new Error('No escalation code defined.'); } const escalationCode = this.escalationEndEvent.escalationEventDefinition?.escalationCode; const escalation = { correlationId: this.processInstance.getCorrelationId(), processDefinitionId: this.processInstance.getProcessDefinitionId(), processModelId: this.processInstance.getProcessModelId(), embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(), processModelName: this.processInstance.getProcessModelName(), processInstanceId: this.processInstance.getProcessInstanceId(), processInstance: this.processInstance, flowNodeId: this.escalationEndEvent.id, flowNodeName: this.escalationEndEvent.name, flowNodeInstanceId: this.flowNodeInstanceId, currentToken: this.processToken, eventName: this.escalationEndEvent.escalationEventDefinition?.name, eventType: this.flowNode.eventType, escalationCode: escalationCode, }; this.logger.debug(`EscalationEndEvent instance now sending escalation ${escalationCode}...`); await this.escalationEventService.throwEscalation(escalation); this.logger.debug('Done.'); return resolve(undefined); } catch (error) { let errorMessageToLog; if (error.category) { errorMessageToLog = `Failure in ${error.category}: Failed to send escalation: ${error.message.replace(`Failure in ${error.category}: `, '')}`; } else { errorMessageToLog = `Failed to send escalation: ${error.message}`; } this.logger.error(errorMessageToLog, { correlationId: this.processInstance.getCorrelationId(), processInstanceId: this.processInstance.getProcessInstanceId(), flowNodeInstanceId: this.flowNodeInstanceId, flowNodeId: this.flowNode.id, }); this.processToken = {}; return reject(error); } }); } }; exports.EndEscalationEventHandler = EndEscalationEventHandler; exports.EndEscalationEventHandler = EndEscalationEventHandler = __decorate([ (0, inversify_1.injectable)(), __metadata("design:paramtypes", [index_2.EventMiddlewareHandler, FlowNodeHandlerFactory_1.FlowNodeHandlerFactory, index_2.FlowNodeInstanceDatabaseAdapter, Object, ProcessInstance_1.ProcessInstance, EscalationEventService_1.EscalationEventService]) ], EndEscalationEventHandler); //# sourceMappingURL=EndEscalationEventHandler.js.map