UNPKG

@5minds/processcube_engine

Version:

The ProcessCube Engine. Stores and executes BPMNs.

109 lines 6.1 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.IntermediateEscalationThrowEventHandler = 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 EventHandler_1 = require("./EventHandler"); let IntermediateEscalationThrowEventHandler = class IntermediateEscalationThrowEventHandler extends EventHandler_1.EventHandler { escalationEventService; constructor(eventMiddlewareHandler, flowNodeHandlerFactory, flowNodeInstanceDatabaseAdapter, intermediateEscalationThrowEventModel, processInstance, escalationEventService) { super(eventMiddlewareHandler, flowNodeHandlerFactory, flowNodeInstanceDatabaseAdapter, intermediateEscalationThrowEventModel, processInstance, 'escalation_throw_event_handler'); this.escalationEventService = escalationEventService; } get escalationThrowEvent() { return this.flowNode; } async persistOnExit() { await super.persistOnExit({ type: index_1.FlowNodeInstanceDataTypes.throwEvent, eventName: this.escalationThrowEvent.escalationEventDefinition?.name, }); this.publishIntermediateThrowEventTriggeredNotification(); } async persistOnError(error) { await super.persistOnError(error, { type: index_1.FlowNodeInstanceDataTypes.throwEvent, eventName: this.escalationThrowEvent.escalationEventDefinition?.name, }); this.publishIntermediateThrowEventTriggeredNotification(); } async persistOnTerminate() { await super.persistOnTerminate({ type: index_1.FlowNodeInstanceDataTypes.throwEvent, eventName: this.escalationThrowEvent.escalationEventDefinition?.name, }); } async startExecution() { this.logger.debug(`Executing escalationThrowEvent instance.`); return this.executeHandler(); } async executeHandler() { try { this.ensureHasClaim(); if (!this.escalationThrowEvent.escalationEventDefinition?.escalationCode) { throw new Error('No escalation code defined.'); } const escalationCode = this.escalationThrowEvent.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.escalationThrowEvent.id, flowNodeName: this.escalationThrowEvent.name, flowNodeInstanceId: this.flowNodeInstanceId, currentToken: this.processToken, eventName: this.escalationThrowEvent.escalationEventDefinition?.name, eventType: this.flowNode.eventType, escalationCode: escalationCode, }; this.logger.debug(`EscalationThrowEvent instance now sending escalation ${escalationCode}...`); await this.escalationEventService.throwEscalation(escalation); this.logger.debug('Done.'); return this.processInstance.getProcessModelFacade().getNextFlowNodesFor(this.escalationThrowEvent); } 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 = {}; throw error; } } }; exports.IntermediateEscalationThrowEventHandler = IntermediateEscalationThrowEventHandler; exports.IntermediateEscalationThrowEventHandler = IntermediateEscalationThrowEventHandler = __decorate([ (0, inversify_1.injectable)(), __metadata("design:paramtypes", [index_2.EventMiddlewareHandler, FlowNodeHandlerFactory_1.FlowNodeHandlerFactory, index_2.FlowNodeInstanceDatabaseAdapter, Object, ProcessInstance_1.ProcessInstance, EscalationEventService_1.EscalationEventService]) ], IntermediateEscalationThrowEventHandler); //# sourceMappingURL=IntermediateEscalationThrowEventHandler.js.map