UNPKG

@5minds/processcube_engine

Version:

The ProcessCube Engine. Stores and executes BPMNs.

113 lines 5.47 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomServiceTaskInstanceHandler = void 0; const _ = __importStar(require("lodash")); const processcube_engine_sdk_1 = require("@5minds/processcube_engine_sdk"); const index_1 = require("../../../Contracts/index"); const AbortablePromise_1 = require("../../../Tools/AbortablePromise"); const ActivityInstanceHandler_1 = require("./ActivityInstanceHandler"); class CustomServiceTaskInstanceHandler extends ActivityInstanceHandler_1.ActivityInstanceHandler { loggerNamespace = 'custom_service_task'; get serviceTask() { return this.flowNode; } async runHandler() { this.logger.debug(`Executing custom ServiceTask instance.`); if (!this.serviceTask.customType) { this.logger.debug(`ServiceTaskHandler not defined. Skipping execution.`); this.currentToken = {}; return; } const containerKey = `${index_1.customServiceTaskPrefix}${this.serviceTask.customType}`; if (!this.processInstance.getContainer().isBound(containerKey)) { throw new processcube_engine_sdk_1.BadRequestError(`No handler for custom service task type \`${this.serviceTask.customType}\` has been registered.`, 'extension'); } const serviceTaskHandler = this.processInstance.getContainer().get(containerKey); await this.persistOnSuspend(); const handlerPromise = new AbortablePromise_1.AbortablePromise(async (resolve, reject) => { try { this.logger.debug(`Executing custom ServiceTask '${this.serviceTask.customType}'`); const serviceTaskHandlerContext = await this.getServiceTaskHandlerContext(); const result = await serviceTaskHandler(serviceTaskHandlerContext); this.currentToken = result; return resolve(); } catch (error) { this.logger.error(error.message, { err: error, }); return reject(error); } }, { signal: this.activityHandler.abortSignal }); return handlerPromise; } async resumeAfterSuspend() { return this.runHandler(); } async getServiceTaskHandlerContext() { const tokenHistoryParams = { processInstanceId: this.processInstance.getProcessInstanceId(), currentToken: this.currentToken, currentFlowNodeId: this.serviceTask.id, previousFlowNodeId: this.processInstance.getProcessModelFacade().getPreviousFlowNodesFor(this.serviceTask)?.pop()?.id, }; const tokenHistory = await this.processInstance.getProcessTokenService().buildTokenHistoryForProcessInstance(tokenHistoryParams); const dataObjectValues = this.processInstance.getDataObjectFacade().getCurrentValues(); const owner = this.processInstance.getOwner(); const identity = { token: owner.token, userId: owner.userId, userToken: owner.token, claims: owner.claims, }; const currentFlowNodeMetadata = processcube_engine_sdk_1.FlowNodeViewModelFactory.getViewModel(this.serviceTask, { processModelId: this.processInstance.getProcessModelId(), processModelName: this.processInstance.getProcessModelName(), }); return { token: _.cloneDeep(tokenHistory), correlationId: this.processInstance.getCorrelationId(), correlationMetadata: this.processInstance.getCorrelationMetaData(), dataObjects: dataObjectValues, currentFlowNode: currentFlowNodeMetadata, identity: identity, processInstanceMetadata: this.processInstance.getProcessInstanceMetaData(), previousFlowNodeId: this.processInstance.getProcessModelFacade().getPreviousFlowNodesFor(this.serviceTask)?.pop()?.id, }; } } exports.CustomServiceTaskInstanceHandler = CustomServiceTaskInstanceHandler; //# sourceMappingURL=CustomServiceTaskInstanceHandler.js.map