UNPKG

@5minds/processcube_engine

Version:

The ProcessCube Engine. Stores and executes BPMNs.

230 lines • 12.5 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 __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowNodeInstanceController = void 0; const inversify_1 = require("inversify"); const processcube_engine_sdk_1 = require("@5minds/processcube_engine_sdk"); const Contracts_1 = require("../../Contracts"); const BaseController_1 = require("./BaseController"); const BuildErrorObject_1 = require("./BuildErrorObject"); let FlowNodeInstanceController = class FlowNodeInstanceController extends BaseController_1.BaseController { flowNodeInstanceServiceProxy; constructor(flowNodeInstanceServiceProxy) { super(); this.logger = new processcube_engine_sdk_1.Logger('api:http:flownode_instance_controller'); this.flowNodeInstanceServiceProxy = flowNodeInstanceServiceProxy; } async finishUntypedTask(request, response) { const identity = request.identity; const taskInstanceId = request.params.untyped_task_instance_id; this.logger.debug('Received `finish untyped task` http request', { taskInstanceId: taskInstanceId, }); await this.flowNodeInstanceServiceProxy.finishUntypedTask(identity, taskInstanceId); response.status(this.httpCodeSuccessNoContentResponse).send(); } async finishManualTask(request, response) { const identity = request.identity; const manualTaskInstanceId = request.params.manual_task_instance_id; this.logger.debug('Received `finish manual task` http request', { manualTaskInstanceId: manualTaskInstanceId, }); await this.flowNodeInstanceServiceProxy.finishManualTask(identity, manualTaskInstanceId); response.status(this.httpCodeSuccessNoContentResponse).send(); } async finishUserTask(request, response) { const identity = request.identity; const userTaskInstanceId = request.params.user_task_instance_id; const result = request.body; this.logger.debug('Received `finish user task` http request', { userTaskInstanceId: userTaskInstanceId, result: result, }); await this.flowNodeInstanceServiceProxy.finishUserTask(identity, userTaskInstanceId, result); response.status(this.httpCodeSuccessNoContentResponse).send(); } async triggerMessageEvent(request, response) { const identity = request.identity; const messageName = request.params.event_name; const processInstanceId = request.query.process_instance_id; const customCorrelationId = request.query.custom_correlation_id; const payload = request.body; const eventOptions = { processInstanceId, customCorrelationId, payload, }; this.logger.debug('Received `trigger message event` http request', { messageName, eventOptions, }); await this.flowNodeInstanceServiceProxy.triggerMessageEvent(identity, messageName, eventOptions); response.status(this.httpCodeSuccessNoContentResponse).send(); } async triggerSignalEvent(request, response) { const identity = request.identity; const signalName = request.params.event_name; const processInstanceId = request.query.process_instance_id; const customCorrelationId = request.query.custom_correlation_id; const payload = request.body; const eventOptions = { processInstanceId, customCorrelationId, payload, }; this.logger.debug('Received `trigger signal event` http request', { signalName, eventOptions, }); await this.flowNodeInstanceServiceProxy.triggerSignalEvent(identity, signalName, eventOptions); response.status(this.httpCodeSuccessNoContentResponse).send(); } async triggerTimerEvent(request, response) { const identity = request.identity; const flowNodeInstanceId = request.params.flow_node_instance_id; this.logger.debug('Received `trigger timer event` http request', { flowNodeInstanceId: flowNodeInstanceId, }); await this.flowNodeInstanceServiceProxy.triggerTimerEvent(identity, flowNodeInstanceId); response.status(this.httpCodeSuccessNoContentResponse).send(); } async query(request, response) { const identity = request.identity; const offset = this.parseOffset(request); const limit = this.parseLimit(request); const sortSettings = this.parseSortSettings(request); const includeCount = request.query.includeCount == null || request.query.includeCount === 'true'; this.validateFlowNodeInstanceQuery(request.query); const flowNodeInstanceQuery = this.buildFlowNodeInstanceQuery(request.query); this.logger.debug('Received `flow node instance query` http request', { offset: offset, limit: limit, sortSettings: sortSettings, flowNodeInstanceQuery: flowNodeInstanceQuery, includeCount: includeCount, }); const flowNodeInstances = await this.flowNodeInstanceServiceProxy.query(identity, flowNodeInstanceQuery, offset, limit, sortSettings, includeCount); const serializeFlowNodeInstanceForTransport = (flowNodeInstance) => { let serializedExternalTaskData; if (flowNodeInstance.externalTaskData) { serializedExternalTaskData = { ...flowNodeInstance.externalTaskData, error: (0, BuildErrorObject_1.buildErrorObject)(flowNodeInstance.externalTaskData.error), }; } return { ...flowNodeInstance, externalTaskData: serializedExternalTaskData, error: (0, BuildErrorObject_1.buildErrorObject)(flowNodeInstance.error), startToken: flowNodeInstance.startToken instanceof Error ? (0, BuildErrorObject_1.buildErrorObject)(flowNodeInstance.startToken) : flowNodeInstance.startToken, endToken: flowNodeInstance.endToken instanceof Error ? (0, BuildErrorObject_1.buildErrorObject)(flowNodeInstance.endToken) : flowNodeInstance.endToken, }; }; const serializedData = { flowNodeInstances: flowNodeInstances.flowNodeInstances.map(serializeFlowNodeInstanceForTransport), totalCount: flowNodeInstances.totalCount, }; response.status(this.httpCodeSuccessfulResponse).send(serializedData); } async reserveUserTaskInstance(request, response) { const identity = request.identity; const flowNodeInstanceId = request.params.user_task_instance_id; const actualOwnerId = request.body.actualOwnerId; this.logger.debug('Received `reserve user task instance` http request', { flowNodeInstanceId: flowNodeInstanceId, actualOwnerId: actualOwnerId, }); await this.flowNodeInstanceServiceProxy.reserveUserTaskInstance(identity, flowNodeInstanceId, actualOwnerId); response.status(this.httpCodeSuccessNoContentResponse).send(); } async cancelUserTaskInstanceReservation(request, response) { const identity = request.identity; const flowNodeInstanceId = request.params.user_task_instance_id; this.logger.debug('Received `cancel user task instance reservation` http request', { userTaskInstanceId: flowNodeInstanceId, }); await this.flowNodeInstanceServiceProxy.cancelUserTaskInstanceReservation(identity, flowNodeInstanceId); response.status(this.httpCodeSuccessNoContentResponse).send(); } validateFlowNodeInstanceQuery(queryParams) { if (queryParams.state) { const queriedStates = queryParams.state.indexOf(',') > 0 ? queryParams.state.split(',') : [queryParams.state]; const flowNodeInstanceStates = Object.values(processcube_engine_sdk_1.FlowNodeInstanceState); for (const queriedState of queriedStates) { if (!flowNodeInstanceStates.includes(queriedState)) { const error = new processcube_engine_sdk_1.BadRequestError(`'${queriedState}' is not a valid FlowNodeInstance state!`); error.additionalInformation = { queriedStates: queriedStates, allowedStates: flowNodeInstanceStates, }; throw error; } } } } buildFlowNodeInstanceQuery(queryParams) { const query = { flowNodeInstanceId: this.getQueryParamValue(queryParams.flowNodeInstanceId), flowNodeId: this.getQueryParamValue(queryParams.flowNodeId), flowNodeName: this.getQueryParamValue(queryParams.flowNodeName), flowNodeLane: this.getQueryParamValue(queryParams.flowNodeLane), flowNodeType: this.getQueryParamValue(queryParams.flowNodeType), eventType: this.getQueryParamValue(queryParams.eventType), correlationId: this.getQueryParamValue(queryParams.correlationId), processDefinitionId: this.getQueryParamValue(queryParams.processDefinitionId), processModelId: this.getQueryParamValue(queryParams.processModelId), embeddedProcessModelId: this.getQueryParamValue(queryParams.embeddedProcessModelId), processModelName: this.getQueryParamValue(queryParams.processModelName), processInstanceId: this.getQueryParamValue(queryParams.processInstanceId), ownerId: this.getQueryParamValue(queryParams.ownerId), state: this.getQueryParamValueAsEnum(queryParams.state, processcube_engine_sdk_1.FlowNodeInstanceState), previousFlowNodeInstanceId: this.getQueryParamValue(queryParams.previousFlowNodeInstanceId), parentProcessInstanceId: this.getQueryParamValue(queryParams.parentProcessInstanceId), createdAt: this.getQueryParamValueAsDate(queryParams.createdAt), updatedAt: this.getQueryParamValueAsDate(queryParams.updatedAt), triggeredByFlowNodeInstanceId: this.getQueryParamValue(queryParams.triggeredByFlowNodeInstance), }; return query; } parseOffset(request) { const parsedOffset = parseInt(request.query?.offset); return Number.isNaN(parsedOffset) ? 0 : parsedOffset; } parseLimit(request) { const parsedLimit = parseInt(request.query?.limit); return Number.isNaN(parsedLimit) ? 0 : parsedLimit; } parseSortSettings(request) { if (request.query?.sortBy || request.query?.sortDir) { return { sortBy: request.query?.sortBy ?? processcube_engine_sdk_1.FlowNodeInstanceSortableColumns.createdAt, sortDir: request.query?.sortDir ?? 'DESC', }; } if (!request.query?.sortSettings) { return { sortBy: processcube_engine_sdk_1.FlowNodeInstanceSortableColumns.createdAt, sortDir: 'DESC', }; } return JSON.parse(decodeURIComponent(request.query.sortSettings)); } }; exports.FlowNodeInstanceController = FlowNodeInstanceController; exports.FlowNodeInstanceController = FlowNodeInstanceController = __decorate([ (0, inversify_1.injectable)(), __param(0, (0, inversify_1.inject)(Contracts_1.IocRegistrationKeys.api.services.FlowNodeInstanceServiceProxy)), __metadata("design:paramtypes", [Object]) ], FlowNodeInstanceController); //# sourceMappingURL=FlowNodeInstanceController.js.map