@5minds/processcube_engine
Version:
The ProcessCube Engine. Stores and executes BPMNs.
620 lines • 34 kB
JavaScript
"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;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActivityInstanceHandler = void 0;
const dayjs = __importStar(require("dayjs"));
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
const uuid = __importStar(require("uuid"));
const processcube_engine_sdk_1 = require("@5minds/processcube_engine_sdk");
const Contracts_1 = require("../../../Contracts");
const Tools_1 = require("../../../Tools");
class ActivityInstanceHandler {
flowNodeInstanceDatabaseAdapter;
eventMiddlewareHandler;
instanceContext = {};
activityHandler;
processInstance;
triggeredByFlowNodeInstanceId;
typeData;
logger;
loggingMetaData = {};
loggerNamespace = 'activity_instance_handler';
currentToken;
previousFlowNodeInstanceId;
_state;
_flowNodeInstanceId;
startedAt;
finishedAt;
tokenChangedSubscription;
constructor(eventMiddlewareHandler, flowNodeInstanceDatabaseAdapter, activityHandler, processInstance, previousFlowNodeInstanceId, instanceContext) {
this.flowNodeInstanceDatabaseAdapter = flowNodeInstanceDatabaseAdapter;
this.eventMiddlewareHandler = eventMiddlewareHandler;
this.activityHandler = activityHandler;
this.processInstance = processInstance;
this.previousFlowNodeInstanceId = previousFlowNodeInstanceId;
this.flowNodeInstanceId = uuid.v4();
this.instanceContext = instanceContext ?? this.instanceContext;
this.logger = new processcube_engine_sdk_1.Logger(this.loggerNamespace, this.loggingMetaData);
}
get flowNodeInstanceId() {
return this._flowNodeInstanceId;
}
set flowNodeInstanceId(value) {
this._flowNodeInstanceId = value;
}
get state() {
return this._state;
}
set state(value) {
this._state = value;
}
get flowNode() {
return this.activityHandler.flowNode;
}
get flowNodeLane() {
return this.processInstance.getProcessModelFacade().getLaneForFlowNode(this.flowNode.id);
}
get owner() {
return this.processInstance.getOwner();
}
initFromFlowNodeInstance(fni) {
this.flowNodeInstanceId = fni.flowNodeInstanceId;
this.state = fni.state;
this.currentToken = fni.endToken ?? fni.startToken;
this.startedAt = fni.startedAt;
this.finishedAt = fni.finishedAt;
this.triggeredByFlowNodeInstanceId = fni.triggeredByFlowNodeInstance?.flowNodeInstanceId;
}
async execute(startToken, executionCanceledCallback) {
this.activityHandler.abortSignal.throwIfAborted();
try {
await this.beforeExecute();
this.currentToken = startToken;
await this.persistOnEnter();
this.publishActivityReachedNotification();
await this.runHandler(executionCanceledCallback);
await this.finishActivity();
return this.currentToken;
}
catch (error) {
await this.handleActivityError(error);
}
finally {
await this.afterExecute();
this.publishActivityFinishedNotification();
}
}
async resume(flowNodeInstanceForHandler, resumptionCanceledCallback) {
this.activityHandler.abortSignal.throwIfAborted();
this.state = flowNodeInstanceForHandler.state;
this.startedAt = flowNodeInstanceForHandler.startedAt;
this.previousFlowNodeInstanceId = flowNodeInstanceForHandler.previousFlowNodeInstanceId;
this.flowNodeInstanceId = flowNodeInstanceForHandler.flowNodeInstanceId;
try {
await this.beforeExecute();
this.publishActivityReachedNotification();
await this.resumeFromState(flowNodeInstanceForHandler, resumptionCanceledCallback);
return this.currentToken;
}
catch (error) {
await this.handleActivityError(error);
}
finally {
await this.afterExecute();
this.publishActivityFinishedNotification();
}
}
async handleActivityError(error) {
const isAbortError = error.name === 'AbortError' || error.type === 'abort';
if (isAbortError) {
return;
}
await this.persistOnError(error);
throw error;
}
async endWithError(error, force = false) {
return this.persistOnError(error, undefined, force);
}
async terminate() {
return this.persistOnTerminate();
}
async cancel() {
await this.afterExecute();
return this.persistOnCancel();
}
async persistOnEnter() {
this.activityHandler.abortSignal.throwIfAborted();
this.state = processcube_engine_sdk_1.FlowNodeInstanceState.running;
const persistOnEnterRequest = {
flowNodeInstanceId: this.flowNodeInstanceId,
flowNodeId: this.flowNode.id,
flowNodeType: this.flowNode.bpmnType,
flowNodeName: this.flowNode.name,
flowNodeLane: this.flowNodeLane?.name ?? '',
eventType: this.flowNode.eventType,
correlationId: this.processInstance.getCorrelationId(),
processDefinitionId: this.processInstance.getProcessDefinitionId(),
processModelId: this.processInstance.getProcessModelId(),
embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(),
processInstanceId: this.processInstance.getProcessInstanceId(),
ownerId: this.owner.userId,
currentToken: this.currentToken,
previousFlowNodeInstanceId: this.previousFlowNodeInstanceId,
parentProcessInstanceId: this.processInstance.getParentProcessInstance()?.getProcessInstanceId(),
flowNodeInstanceTypeData: this.typeData,
multiInstanceMetadataId: this.activityHandler.multiInstanceMetadataId,
triggeredByFlowNodeInstanceId: this.typeData?.triggeredByFlowNodeInstanceId,
};
try {
if (this.flowNode.loopMarker === processcube_engine_sdk_1.Model.Activities.LoopMarker.Parallel) {
await new Promise(async (resolve) => {
await this.activityHandler.batchPersistOnEnterRequest(persistOnEnterRequest, this.instanceContext.totalLoopElements ?? 1, resolve);
});
}
else {
await this.flowNodeInstanceDatabaseAdapter.persistOnEnter(persistOnEnterRequest);
}
this.startedAt = dayjs.utc().toDate();
const metadata = await this.executeRuntimePropertyExpressionsOnFlowNode(this.currentToken);
await this.logFlowNodePersistenceEvent(processcube_engine_sdk_1.EngineEventType.OnFlowNodeEntered, processcube_engine_sdk_1.LogLevel.debug, {
writtenCorrelationMetadata: metadata.correlationMetdata,
writtenProcessInstanceMetadata: metadata.processInstanceMetadata,
triggeredByFlowNodeInstanceId: this.triggeredByFlowNodeInstanceId,
});
}
catch (error) {
// Note that we can only persist an error state, if the Flow Node Instance was already persisted through "persistOnEnter".
// Running this multiple times is safe, because a second persistOnEnter will do nothing but update the "previousFlowNodeInstanceId" property
await this.flowNodeInstanceDatabaseAdapter.persistOnEnter(persistOnEnterRequest);
throw error;
}
}
async persistOnSuspend(updatedTokenPayload, typeData) {
this.state = processcube_engine_sdk_1.FlowNodeInstanceState.suspended;
const data = {
tokenPayload: updatedTokenPayload,
typeData: typeData,
};
await this.flowNodeInstanceDatabaseAdapter.persistOnSuspend(this.flowNodeInstanceId, data);
await this.logFlowNodePersistenceEvent(processcube_engine_sdk_1.EngineEventType.OnFlowNodeSuspended, processcube_engine_sdk_1.LogLevel.debug);
}
async persistOnExit(dataObjectValues, typeData) {
this.activityHandler.abortSignal.throwIfAborted();
this.state = processcube_engine_sdk_1.FlowNodeInstanceState.finished;
this.finishedAt = dayjs.utc().toDate();
const data = {
finishedAt: this.finishedAt,
tokenPayload: this.currentToken,
typeData: typeData,
dataObjectValues: dataObjectValues,
triggeredByFlowNodeInstanceId: typeData?.triggeredByFlowNodeInstanceId,
};
await this.flowNodeInstanceDatabaseAdapter.persistOnExit(this.flowNodeInstanceId, data);
await this.logFlowNodePersistenceEvent(processcube_engine_sdk_1.EngineEventType.OnFlowNodeExited, processcube_engine_sdk_1.LogLevel.debug, { writtenDataObjectValues: dataObjectValues });
}
async persistOnError(error, typeData, force = false) {
// This check is necessary, in case the Promise-Chain was broken further down the road.
if (!(this.state === processcube_engine_sdk_1.FlowNodeInstanceState.running || this.state === processcube_engine_sdk_1.FlowNodeInstanceState.suspended) && !force) {
return;
}
this.state = processcube_engine_sdk_1.FlowNodeInstanceState.error;
this.finishedAt = dayjs.utc().toDate();
const data = {
finishedAt: this.finishedAt,
tokenPayload: this.currentToken,
error: error,
typeData: typeData,
};
await this.flowNodeInstanceDatabaseAdapter.persistOnError(this.flowNodeInstanceId, data);
Tools_1.EventAggregator.publish(Contracts_1.eventAggregatorSettings.messagePaths.activityError, {
correlationId: this.processInstance.getCorrelationId(),
processDefinitionId: this.processInstance.getProcessDefinitionId(),
processModelId: this.processInstance.getProcessModelId(),
embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(),
processModelName: this.processInstance.getProcessModelName(),
processInstanceId: this.processInstance.getProcessInstanceId(),
parentProcessInstanceId: this.processInstance.getParentProcessInstance()?.getProcessInstanceId(),
flowNodeId: this.flowNode.id,
flowNodeName: this.flowNode.name,
flowNodeType: this.flowNode.bpmnType,
flowNodeInstanceId: this.flowNodeInstanceId,
processInstanceOwner: this.processInstance.getOwner(),
currentToken: this.currentToken,
previousFlowNodeInstanceId: this.previousFlowNodeInstanceId,
error: {
name: error.name,
code: error.code,
message: error.message,
category: error.category,
fatal: error.fatal,
},
});
await this.logFlowNodePersistenceEvent(processcube_engine_sdk_1.EngineEventType.OnFlowNodeError, processcube_engine_sdk_1.LogLevel.error);
}
async persistOnCancel(typeData) {
this.state = processcube_engine_sdk_1.FlowNodeInstanceState.canceled;
this.finishedAt = dayjs.utc().toDate();
const data = {
finishedAt: this.finishedAt,
tokenPayload: this.currentToken,
typeData: typeData,
};
await this.flowNodeInstanceDatabaseAdapter.persistOnCancel(this.flowNodeInstanceId, data);
await this.logFlowNodePersistenceEvent(processcube_engine_sdk_1.EngineEventType.OnFlowNodeCanceled, processcube_engine_sdk_1.LogLevel.debug);
this.publishActivityCanceledNotification();
}
async persistOnTerminate(typeData) {
// This check is necessary, in case the Promise-Chain was broken further down the road.
if (!(this.state === processcube_engine_sdk_1.FlowNodeInstanceState.running || this.state === processcube_engine_sdk_1.FlowNodeInstanceState.suspended)) {
return;
}
this.state = processcube_engine_sdk_1.FlowNodeInstanceState.terminated;
this.finishedAt = dayjs.utc().toDate();
const data = {
finishedAt: this.finishedAt,
tokenPayload: this.currentToken,
typeData: typeData,
};
await this.flowNodeInstanceDatabaseAdapter.persistOnTerminate(this.flowNodeInstanceId, data);
await this.logFlowNodePersistenceEvent(processcube_engine_sdk_1.EngineEventType.OnFlowNodeTerminated, processcube_engine_sdk_1.LogLevel.error);
}
async beforeExecute() {
this.subscribeToMiddlewareEvent();
return Promise.resolve();
}
async afterExecute() {
Tools_1.EventAggregator.unsubscribe(this.tokenChangedSubscription);
}
async runHandler(_executionCanceledCallback) {
this.activityHandler.abortSignal.throwIfAborted();
}
async resumeFromState(flowNodeInstance, executionCanceledCallback) {
this.activityHandler.abortSignal.throwIfAborted();
this.logger.debug(`Resuming FlowNodeInstance.`, {
correlationId: this.processInstance.getCorrelationId(),
processInstanceId: this.processInstance.getProcessInstanceId(),
flowNodeInstanceId: flowNodeInstance.flowNodeInstanceId,
});
switch (flowNodeInstance.state) {
case processcube_engine_sdk_1.FlowNodeInstanceState.suspended:
this.logger.debug('Activity was left suspended. Waiting for the resuming event to happen.');
this.currentToken = flowNodeInstance.startToken;
await this.resumeAfterSuspend(flowNodeInstance, executionCanceledCallback);
await this.finishActivity();
return;
case processcube_engine_sdk_1.FlowNodeInstanceState.running:
this.logger.debug('Activity was interrupted at the beginning. Resuming from the start.');
this.currentToken = flowNodeInstance.startToken;
await this.runHandler(executionCanceledCallback);
await this.finishActivity();
return;
case processcube_engine_sdk_1.FlowNodeInstanceState.finished:
this.logger.debug('Activity was already finished. Skipping ahead.');
this.currentToken = flowNodeInstance.endToken;
return;
case processcube_engine_sdk_1.FlowNodeInstanceState.error:
this.logger.error(`Cannot resume Activity, because it previously exited with an error!`, {
err: flowNodeInstance.error,
processInstanceId: this.processInstance.getProcessInstanceId(),
correlationId: this.processInstance.getCorrelationId(),
});
// Resetting the state here will cause the error handler to run again, thus triggering and handling all possible boundary events.
this.state = processcube_engine_sdk_1.FlowNodeInstanceState.suspended;
throw flowNodeInstance.error;
case processcube_engine_sdk_1.FlowNodeInstanceState.terminated:
const terminatedError = new processcube_engine_sdk_1.InternalServerError(`Cannot resume Activity, because it was terminated!`);
terminatedError.additionalInformation = {
processInstanceId: this.processInstance.getProcessInstanceId(),
correlationId: this.processInstance.getCorrelationId(),
};
this.logger.error(terminatedError.message);
throw terminatedError;
case processcube_engine_sdk_1.FlowNodeInstanceState.canceled:
this.logger.warn(`Cannot resume Activity, because it was canceled.`);
return;
default:
const invalidStateError = new processcube_engine_sdk_1.InternalServerError(`Cannot resume Activity, because its state cannot be determined!`);
invalidStateError.additionalInformation = {
processInstanceId: this.processInstance.getProcessInstanceId(),
correlationId: this.processInstance.getCorrelationId(),
};
this.logger.error(invalidStateError.message);
throw invalidStateError;
}
}
/**
* Hook for resuming a Flow Node Handler that is currently in a suspended state.
*/
async resumeAfterSuspend(flowNodeInstance, resumptionCanceledCallback) {
this.activityHandler.abortSignal.throwIfAborted();
return Promise.resolve();
}
async finishActivity() {
this.activityHandler.abortSignal.throwIfAborted();
let dataObjectValues = undefined;
if (!this.activityHandler.isMultiInstanceType()) {
this.currentToken = (await this.activityHandler.runPostScript(this.currentToken)) ?? this.currentToken;
dataObjectValues = await this.activityHandler.runOutgoingDataObjectExpressions(this.currentToken);
}
await this.persistOnExit(dataObjectValues);
}
ensureHasClaim() {
const processModelHasNoLanes = !this.processInstance.getProcessModelFacade().getProcessModelHasLanes();
const processWasStartedByRootAccessToken = this.processInstance.getStartedByRootAccessToken();
if (processModelHasNoLanes || processWasStartedByRootAccessToken) {
return;
}
const laneForFlowNode = this.processInstance.getProcessModelFacade().getLaneForFlowNode(this.flowNode.id);
const claimName = laneForFlowNode.name;
if (claimName) {
this.processInstance.ensureOwnerHasClaim(claimName);
}
}
async executeRuntimeExpressionOnInstanceContext(config) {
const mergedAdditionalProperties = config.additionalProperties ? { ...config.additionalProperties, ...this.instanceContext } : { ...this.instanceContext };
const configWithInstanceContext = { ...config, additionalProperties: mergedAdditionalProperties };
const result = await this.processInstance.executeRuntimeExpression(configWithInstanceContext);
return result;
}
async postEventToEventMiddlewares(payload) {
const runtimeExpressionParameters = this.processInstance.buildRuntimeExpressionDataForFlowNodeInstance({
currentFlowNode: this.flowNode,
currentToken: this.currentToken,
previousFlowNode: this.processInstance.getProcessModelFacade().getPreviousFlowNodesFor(this.flowNode)?.pop(),
allowNonObjectResults: false,
});
await this.eventMiddlewareHandler.triggerEvent((0, lodash_clonedeep_1.default)(payload), runtimeExpressionParameters);
}
subscribeToMiddlewareEvent() {
const tokenPayloadChangeMessagePath = Contracts_1.eventAggregatorSettings.messagePaths.tokenPayloadChange.replace(Contracts_1.eventAggregatorSettings.messageParams.flowNodeInstanceId, this.flowNodeInstanceId);
const tokenPayloadChangeFinishedMessagePath = Contracts_1.eventAggregatorSettings.messagePaths.tokenPayloadChangeFinished.replace(Contracts_1.eventAggregatorSettings.messageParams.flowNodeInstanceId, this.flowNodeInstanceId);
this.tokenChangedSubscription = Tools_1.EventAggregator.subscribe(tokenPayloadChangeMessagePath, async (tokenChangeEvent) => {
this.currentToken = tokenChangeEvent.tokenPayload ? { ...tokenChangeEvent.tokenPayload } : {};
const tokenTypeToChange = tokenChangeEvent.eventType === processcube_engine_sdk_1.EngineEventType.OnFlowNodeExited ||
tokenChangeEvent.eventType === processcube_engine_sdk_1.EngineEventType.OnFlowNodeError ||
tokenChangeEvent.eventType === processcube_engine_sdk_1.EngineEventType.OnFlowNodeCanceled ||
tokenChangeEvent.eventType === processcube_engine_sdk_1.EngineEventType.OnFlowNodeTerminated
? 'endToken'
: 'startToken';
await this.flowNodeInstanceDatabaseAdapter.changeProcessTokenPayload(this.flowNodeInstanceId, tokenTypeToChange, this.currentToken);
Tools_1.EventAggregator.publish(tokenPayloadChangeFinishedMessagePath);
});
}
/**
* Executes all expressions for updating some meta property on the containing ProcessInstance.
* For example "engine.setProcessInstanceMetadata.propertyName" or "engine.setCorrelationMetadata.propertyName".
*
* These expressions can be found within the FlowNode's extension properties.
*
* @async
*/
async executeRuntimePropertyExpressionsOnFlowNode(token) {
this.activityHandler.abortSignal.throwIfAborted();
const correlationMetdata = await this.setCorrelationMetadata(token);
const processInstanceMetadata = await this.setProcessInstanceMetadata(token);
return {
correlationMetdata,
processInstanceMetadata,
};
}
async setCorrelationMetadata(token) {
const correlationMetadataProperties = this.flowNode.extensionElements?.camundaExtensionProperties?.filter((property) => property.name.startsWith('engine.setCorrelationMetadata.')) ?? [];
if (!correlationMetadataProperties || correlationMetadataProperties.length == 0) {
return;
}
const changedMetaData = {};
for (const property of correlationMetadataProperties) {
if (!property.value || property.value.trim().length === 0) {
continue;
}
const metadataKey = property.name.replace('engine.setCorrelationMetadata.', '').trim();
if (!metadataKey) {
const correlationPropertyNameMissing = new processcube_engine_sdk_1.BadRequestError("Must provide a name with 'engine.setCorrelationMetadata' expressions!", 'process');
correlationPropertyNameMissing.additionalInformation = {
processInstanceId: this.processInstance.getProcessInstanceId(),
correlationId: this.processInstance.getCorrelationId(),
flowNodeId: this.flowNode.id,
flowNodeName: this.flowNode.name,
metaDataKey: metadataKey,
};
throw correlationPropertyNameMissing;
}
changedMetaData[metadataKey] = await this.processInstance.setCorrelationMetadataValue(metadataKey, property.value, this.flowNode, this.flowNodeInstanceId, token);
}
await this.publishCorrelationMetadataChangedNotification(changedMetaData);
return changedMetaData;
}
async setProcessInstanceMetadata(token) {
const processMetadataProperties = this.flowNode.extensionElements?.camundaExtensionProperties?.filter((property) => property.name.startsWith('engine.setProcessInstanceMetadata.')) ?? [];
if (!processMetadataProperties || processMetadataProperties.length == 0) {
return;
}
const changedMetaData = {};
for (const property of processMetadataProperties) {
if (!property.value || property.value.trim().length === 0) {
continue;
}
const metadataKey = property.name.replace('engine.setProcessInstanceMetadata.', '').trim();
if (!metadataKey) {
const processInstancePropertyNameMissing = new processcube_engine_sdk_1.BadRequestError("Must provide a name with 'engine.setProcessInstanceMetadata' expressions!", 'process');
processInstancePropertyNameMissing.additionalInformation = {
processInstanceId: this.processInstance.getProcessInstanceId(),
correlationId: this.processInstance.getCorrelationId(),
flowNodeId: this.flowNode.id,
flowNodeName: this.flowNode.name,
metaDataKey: metadataKey,
};
throw processInstancePropertyNameMissing;
}
changedMetaData[metadataKey] = await this.processInstance.setProcessInstanceMetadataValue(metadataKey, property.value, this.flowNode, this.flowNodeInstanceId, token);
}
this.publishProcessInstanceMetadataChangedNotification(changedMetaData);
return changedMetaData;
}
async logFlowNodePersistenceEvent(eventType, logLevel, additionalData = {}) {
const now = dayjs.utc().toDate();
await this.postEventToEventMiddlewares({
correlationId: this.processInstance.getCorrelationId(),
eventType: eventType,
flowNodeId: this.flowNode.id,
flowNodeName: this.flowNode.name,
flowNodeType: this.flowNode.bpmnType,
flowNodeLane: this.processInstance.getProcessModelFacade().getLaneForFlowNode(this.flowNode.id)?.name,
flowNodeInstanceId: this.flowNodeInstanceId,
currentFlowNode: this.activityHandler.viewModel,
logLevel: logLevel,
processInstanceId: this.processInstance.getProcessInstanceId(),
parentProcessInstanceId: this.processInstance.getParentProcessInstance()?.getProcessInstanceId(),
processDefinitionId: this.processInstance.getProcessDefinitionId(),
processDefinitionHash: this.processInstance.getProcessDefinitionHash(),
processModelId: this.processInstance.getProcessModelId(),
embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(),
processModelName: this.processInstance.getProcessModelName(),
timestamp: now,
flowNodeEnteredAt: this.startedAt,
flowNodeExitedAt: this.finishedAt,
processStartedAt: this.processInstance.getStartedAt(),
tokenPayload: this.currentToken,
...additionalData,
});
}
publishActivityReachedNotification() {
const message = {
correlationId: this.processInstance.getCorrelationId(),
processDefinitionId: this.processInstance.getProcessDefinitionId(),
processModelId: this.processInstance.getProcessModelId(),
embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(),
processModelName: this.processInstance.getProcessModelName(),
processInstanceId: this.processInstance.getProcessInstanceId(),
parentProcessInstanceId: this.processInstance.getParentProcessInstance()?.getProcessInstanceId(),
flowNodeId: this.flowNode.id,
flowNodeName: this.flowNode.name,
flowNodeType: this.flowNode.bpmnType,
flowNodeLane: this.processInstance.getProcessModelFacade().getLaneForFlowNode(this.flowNode.id)?.name,
flowNodeInstanceId: this.flowNodeInstanceId,
processInstanceOwner: this.processInstance.getOwner(),
currentToken: this.currentToken,
previousFlowNodeInstanceId: this.previousFlowNodeInstanceId,
};
Tools_1.EventAggregator.publish(Contracts_1.eventAggregatorSettings.messagePaths.activityReached, message);
}
publishActivityFinishedNotification() {
const message = {
correlationId: this.processInstance.getCorrelationId(),
processDefinitionId: this.processInstance.getProcessDefinitionId(),
processModelId: this.processInstance.getProcessModelId(),
embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(),
processModelName: this.processInstance.getProcessModelName(),
processInstanceId: this.processInstance.getProcessInstanceId(),
parentProcessInstanceId: this.processInstance.getParentProcessInstance()?.getProcessInstanceId(),
flowNodeId: this.flowNode.id,
flowNodeName: this.flowNode.name,
flowNodeType: this.flowNode.bpmnType,
flowNodeLane: this.processInstance.getProcessModelFacade().getLaneForFlowNode(this.flowNode.id)?.name,
flowNodeInstanceId: this.flowNodeInstanceId,
processInstanceOwner: this.processInstance.getOwner(),
currentToken: this.currentToken,
previousFlowNodeInstanceId: this.previousFlowNodeInstanceId,
};
Tools_1.EventAggregator.publish(Contracts_1.eventAggregatorSettings.messagePaths.activityFinished, message);
}
publishActivityCanceledNotification() {
const message = {
correlationId: this.processInstance.getCorrelationId(),
processDefinitionId: this.processInstance.getProcessDefinitionId(),
processModelId: this.processInstance.getProcessModelId(),
embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(),
processModelName: this.processInstance.getProcessModelName(),
processInstanceId: this.processInstance.getProcessInstanceId(),
parentProcessInstanceId: this.processInstance.getParentProcessInstance()?.getProcessInstanceId(),
flowNodeId: this.flowNode.id,
flowNodeName: this.flowNode.name,
flowNodeType: this.flowNode.bpmnType,
flowNodeLane: this.processInstance.getProcessModelFacade().getLaneForFlowNode(this.flowNode.id)?.name,
flowNodeInstanceId: this.flowNodeInstanceId,
processInstanceOwner: this.processInstance.getOwner(),
currentToken: this.currentToken,
previousFlowNodeInstanceId: this.previousFlowNodeInstanceId,
};
Tools_1.EventAggregator.publish(Contracts_1.eventAggregatorSettings.messagePaths.activityCanceled, message);
}
publishProcessInstanceMetadataChangedNotification(changedMetadata) {
const message = {
correlationId: this.processInstance.getCorrelationId(),
processDefinitionId: this.processInstance.getProcessDefinitionId(),
processModelId: this.processInstance.getProcessModelId(),
embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(),
processModelName: this.processInstance.getProcessModelName(),
processInstanceId: this.processInstance.getProcessInstanceId(),
flowNodeId: this.flowNode.id,
flowNodeName: this.flowNode.name,
flowNodeType: this.flowNode.bpmnType,
flowNodeLane: this.processInstance.getProcessModelFacade().getLaneForFlowNode(this.flowNode.id)?.name,
flowNodeInstanceId: this.flowNodeInstanceId,
processInstanceOwner: this.processInstance.getOwner(),
currentToken: this.currentToken ?? {},
changedMetadata: changedMetadata,
};
Tools_1.EventAggregator.publish(Contracts_1.eventAggregatorSettings.messagePaths.processInstanceMetadataChanged, message);
}
async publishCorrelationMetadataChangedNotification(changedMetadata) {
const message = {
correlationId: this.processInstance.getCorrelationId(),
processDefinitionId: this.processInstance.getProcessDefinitionId(),
processModelId: this.processInstance.getProcessModelId(),
embeddedProcessModelId: this.processInstance.getEmbeddedProcessModelId(),
processModelName: this.processInstance.getProcessModelName(),
processInstanceId: this.processInstance.getProcessInstanceId(),
flowNodeId: this.flowNode.id,
flowNodeName: this.flowNode.name,
flowNodeType: this.flowNode.bpmnType,
flowNodeLane: this.processInstance.getProcessModelFacade().getLaneForFlowNode(this.flowNode.id)?.name,
flowNodeInstanceId: this.flowNodeInstanceId,
processInstanceOwner: this.processInstance.getOwner(),
currentToken: this.currentToken ?? {},
changedMetadata: changedMetadata,
};
await new Promise((resolve) => {
const publishMetadataChangesToProcessInstances = Contracts_1.eventAggregatorSettings.messagePaths.changeCorrelationMetadata.replace(Contracts_1.eventAggregatorSettings.messageParams.correlationId, this.processInstance.getCorrelationId());
Tools_1.EventAggregator.publish(publishMetadataChangesToProcessInstances, message, resolve);
});
Tools_1.EventAggregator.publish(Contracts_1.eventAggregatorSettings.messagePaths.correlationMetadataChanged, message);
}
}
exports.ActivityInstanceHandler = ActivityInstanceHandler;
//# sourceMappingURL=ActivityInstanceHandler.js.map