UNPKG

@5minds/processcube_engine

Version:

The ProcessCube Engine. Stores and executes BPMNs.

82 lines 4.71 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.IntermediateLinkThrowEventHandler = 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 ProcessInstance_1 = require("../../ProcessInstance"); const FlowNodeHandlerFactory_1 = require("../FlowNodeHandlerFactory"); const EventHandler_1 = require("./EventHandler"); let IntermediateLinkThrowEventHandler = class IntermediateLinkThrowEventHandler extends EventHandler_1.EventHandler { constructor(eventMiddlewareHandler, flowNodeHandlerFactory, flowNodeInstanceDatabaseAdapter, intermediateLinkThrowModel, processInstance) { super(eventMiddlewareHandler, flowNodeHandlerFactory, flowNodeInstanceDatabaseAdapter, intermediateLinkThrowModel, processInstance, 'link_throw_event_handler'); } get linkThrowEventModel() { return this.flowNode; } async persistOnEnter() { await super.persistOnEnter(undefined, { type: index_1.FlowNodeInstanceDataTypes.throwEvent, eventName: this.linkThrowEventModel.linkEventDefinition.name, }); } async persistOnExit() { await super.persistOnExit(); this.publishIntermediateThrowEventTriggeredNotification(); } async persistOnError(error) { await super.persistOnError(error); this.publishIntermediateThrowEventTriggeredNotification(); } async startExecution() { this.logger.debug(`Executing LinkThrowEvent instance.`); return this.executeHandler(); } async executeHandler() { const matchingCatchEvent = await this.getMatchingCatchEvent(); return [matchingCatchEvent]; } async getMatchingCatchEvent() { const matchingCatchEvents = this.processInstance.getProcessModelFacade().getLinkCatchEventsByLinkName(this.linkThrowEventModel.linkEventDefinition.name); const noMatchingLinkCatchEventExists = !(matchingCatchEvents?.length > 0); if (noMatchingLinkCatchEventExists) { const errorToThrow = new processcube_engine_sdk_1.NotFoundError(`No IntermediateCatchEvent with a link called '${this.linkThrowEventModel.linkEventDefinition.name}' exists!`, 'process'); errorToThrow.additionalInformation = { processInstanceId: this.processInstance.getProcessInstanceId(), correlationId: this.processInstance.getCorrelationId(), }; this.logger.error(errorToThrow.message); throw errorToThrow; } // By BPMN Specs, each IntermediateLinkCatchEvent must use a unique link name. const tooManyMatchingLinkCatchEvents = matchingCatchEvents.length > 1; if (tooManyMatchingLinkCatchEvents) { const errorToThrow = new processcube_engine_sdk_1.BadRequestError(`Too many CatchEvents for link '${this.linkThrowEventModel.linkEventDefinition.name}' exist!`, 'process'); errorToThrow.additionalInformation = { processInstanceId: this.processInstance.getProcessInstanceId(), correlationId: this.processInstance.getCorrelationId(), }; this.logger.error(errorToThrow.message); throw errorToThrow; } return matchingCatchEvents[0]; } }; exports.IntermediateLinkThrowEventHandler = IntermediateLinkThrowEventHandler; exports.IntermediateLinkThrowEventHandler = IntermediateLinkThrowEventHandler = __decorate([ (0, inversify_1.injectable)(), __metadata("design:paramtypes", [index_2.EventMiddlewareHandler, FlowNodeHandlerFactory_1.FlowNodeHandlerFactory, index_2.FlowNodeInstanceDatabaseAdapter, Object, ProcessInstance_1.ProcessInstance]) ], IntermediateLinkThrowEventHandler); //# sourceMappingURL=IntermediateLinkThrowEventHandler.js.map