/// <summary> /// In case no process-context is active, this method attempts to extract a process-definition based on the event. In case it's an event related to an entity, this can be deducted by inspecting the /// entity, without additional queries to the database. /// /// If not an entity-related event, the process-definition will be retrieved based on the processDefinitionId (if filled in). This requires an additional query to the database in case not already /// cached. However, queries will only occur when the definition is not yet in the cache, which is very unlikely to happen, unless evicted. /// </summary> /// <param name="event"> /// @return </param> protected internal virtual BpmnModel ExtractBpmnModelFromEvent(IActivitiEvent @event) { BpmnModel result = null; if (result == null && !(@event.ProcessDefinitionId is null)) { IProcessDefinition processDefinition = ProcessDefinitionUtil.GetProcessDefinition(@event.ProcessDefinitionId, true); if (processDefinition != null) { result = Context.ProcessEngineConfiguration.DeploymentManager.ResolveProcessDefinition(processDefinition).BpmnModel; } } return(result); }
public override void HandleEvent(IEventSubscriptionEntity eventSubscription, object payload, ICommandContext commandContext) { if (eventSubscription.ExecutionId is object) { base.HandleEvent(eventSubscription, payload, commandContext); } else if (eventSubscription.ProcessDefinitionId is object) { // Find initial flow element matching the signal start event string processDefinitionId = eventSubscription.ProcessDefinitionId; IProcessDefinition processDefinition = ProcessDefinitionUtil.GetProcessDefinition(processDefinitionId); if (processDefinition == null) { throw new ActivitiObjectNotFoundException("No process definition found for id '" + processDefinitionId + "'", typeof(IProcessDefinition)); } if (processDefinition.Suspended) { throw new ActivitiException("Could not handle signal: process definition with id: " + processDefinitionId + " is suspended"); } Process process = ProcessDefinitionUtil.GetProcess(processDefinitionId); FlowElement flowElement = process.GetFlowElement(eventSubscription.ActivityId, true); if (flowElement == null) { throw new ActivitiException("Could not find matching FlowElement for activityId " + eventSubscription.ActivityId); } // Start process instance via that flow element IDictionary <string, object> variables = null; if (payload is System.Collections.IDictionary) { variables = (IDictionary <string, object>)payload; } ProcessInstanceHelper processInstanceHelper = commandContext.ProcessEngineConfiguration.ProcessInstanceHelper; processInstanceHelper.CreateAndStartProcessInstanceWithInitialFlowElement(processDefinition, null, null, flowElement, process, variables, null, true); } else { throw new ActivitiException("Invalid signal handling: no execution nor process definition set"); } }
protected internal virtual IEventLogEntryEntity CreateEventLogEntry(string type, string processDefinitionId, string processInstanceId, string executionId, string taskId, IDictionary <string, object> data) { IEventLogEntryEntity eventLogEntry = Context.CommandContext.EventLogEntryEntityManager.Create(); eventLogEntry.ProcessDefinitionId = processDefinitionId; eventLogEntry.ProcessInstanceId = processInstanceId; eventLogEntry.ExecutionId = executionId; eventLogEntry.TaskId = taskId; eventLogEntry.Type = type; eventLogEntry.TimeStamp = timeStamp; PutInMapIfNotNull(data, FieldsFields.TIMESTAMP, timeStamp); // Current user string userId = Authentication.AuthenticatedUser.Id; if (userId is object) { eventLogEntry.UserId = userId; PutInMapIfNotNull(data, "userId", userId); } // Current tenant if (!data.ContainsKey(FieldsFields.TENANT_ID) && !string.IsNullOrWhiteSpace(processDefinitionId)) { IProcessDefinition processDefinition = ProcessDefinitionUtil.GetProcessDefinition(processDefinitionId); if (processDefinition != null && !ProcessEngineConfiguration.NO_TENANT_ID.Equals(processDefinition.TenantId)) { PutInMapIfNotNull(data, FieldsFields.TENANT_ID, processDefinition.TenantId); } } try { eventLogEntry.Data = objectMapper.WriteValueAsBytes(data); } catch (Exception e) { log.LogWarning(e, "Could not serialize event data. Data will not be written to the database"); } return(eventLogEntry); }