Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.common.engine.impl.el;

import java.util.Set;

import org.flowable.common.engine.api.variable.VariableContainer;

/**
* A {@link VariableContainer} that carries definition context (definitionId, definitionKey, deploymentId, scopeType, tenantId)
* for expression evaluation when no execution is active (e.g. during deployment).
* This allows EL resolvers to look up the parent deployment and resolve definition-scoped expressions.
*
* @author Christopher Welsch
*/
public class DefinitionVariableContainer implements VariableContainer {

protected String definitionId;
protected String definitionKey;
protected String deploymentId;
protected String scopeType;
protected String tenantId;

public DefinitionVariableContainer(String definitionId, String definitionKey, String deploymentId, String scopeType, String tenantId) {
this.definitionId = definitionId;
this.definitionKey = definitionKey;
this.deploymentId = deploymentId;
this.scopeType = scopeType;
this.tenantId = tenantId;
}

public String getDefinitionId() {
return definitionId;
}

public String getDefinitionKey() {
return definitionKey;
}

public String getDeploymentId() {
return deploymentId;
}

public String getScopeType() {
return scopeType;
}

@Override
public String getTenantId() {
return tenantId;
}

@Override
public boolean hasVariable(String variableName) {
return false;
}

@Override
public Object getVariable(String variableName) {
return null;
}

@Override
public void setVariable(String variableName, Object variableValue) {

}

@Override
public void setTransientVariable(String variableName, Object variableValue) {

}

@Override
public Set<String> getVariableNames() {
return Set.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.flowable.eventsubscription.service.impl.persistence.entity.EventSubscriptionEntity;
import org.flowable.eventsubscription.service.impl.persistence.entity.MessageEventSubscriptionEntity;
import org.flowable.eventsubscription.service.impl.persistence.entity.SignalEventSubscriptionEntity;
import org.flowable.common.engine.impl.el.DefinitionVariableContainer;

/**
* Manages event subscriptions for newly-deployed process definitions and their previous versions.
Expand Down Expand Up @@ -173,7 +174,7 @@ protected void insertSignalEvent(SignalEventDefinition signalEventDefinition, St
EventSubscriptionService eventSubscriptionService = processEngineConfiguration.getEventSubscriptionServiceConfiguration().getEventSubscriptionService();
SignalEventSubscriptionEntity subscriptionEntity = eventSubscriptionService.createSignalEventSubscription();

String signalName = EventDefinitionExpressionUtil.determineSignalName(commandContext, signalEventDefinition, bpmnModel,null);
String signalName = EventDefinitionExpressionUtil.determineSignalName(commandContext, signalEventDefinition, bpmnModel, processDefinition);
subscriptionEntity.setEventName(signalName);

subscriptionEntity.setActivityId(startEvent.getId());
Expand All @@ -191,8 +192,9 @@ protected void insertMessageEvent(MessageEventDefinition messageEventDefinition,

ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
EventSubscriptionService eventSubscriptionService = processEngineConfiguration.getEventSubscriptionServiceConfiguration().getEventSubscriptionService();

// look for subscriptions for the same name in db:
String messageName = EventDefinitionExpressionUtil.determineMessageName(commandContext, messageEventDefinition, null);
String messageName = EventDefinitionExpressionUtil.determineMessageName(commandContext, messageEventDefinition, processDefinition);
List<EventSubscriptionEntity> subscriptionsForSameMessageName = eventSubscriptionService
.findEventSubscriptionsByName(MessageEventHandler.EVENT_HANDLER_TYPE, messageName, processDefinition.getTenantId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,12 @@ protected List<TimerJobEntity> getTimerDeclarations(ProcessDefinitionEntity proc
if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions())) {
EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
if (eventDefinition instanceof TimerEventDefinition timerEventDefinition) {

TimerJobEntity timerJob = TimerUtil.createTimerEntityForTimerEventDefinition(timerEventDefinition, startEvent,
false, null, TimerStartEventJobHandler.TYPE, TimerEventHandler.createConfiguration(startEvent.getId(),
false, processDefinition, TimerStartEventJobHandler.TYPE, TimerEventHandler.createConfiguration(startEvent.getId(),
timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));

if (timerJob != null) {
timerJob.setProcessDefinitionId(processDefinition.getId());

if (processDefinition.getTenantId() != null) {
timerJob.setTenantId(processDefinition.getTenantId());
}
timers.add(timerJob);
}
timers.add(timerJob);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.flowable.bpmn.model.UserTask;
import org.flowable.bpmn.model.ValuedDataObject;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.impl.el.DefinitionVariableContainer;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
Expand Down Expand Up @@ -1585,7 +1586,10 @@ protected void processCreatedEventSubProcess(EventSubProcess eventSubProcess, Ex
messageExecution.setEventScope(true);
messageExecution.setActive(false);

String messageName = EventDefinitionExpressionUtil.determineMessageName(commandContext, messageEventDefinition, null);
DefinitionVariableContainer definitionVariableContainer = new DefinitionVariableContainer(messageExecution.getProcessDefinitionId(),
messageExecution.getProcessDefinitionKey(), eventSubProcessExecution.getDeploymentId(), ScopeTypes.BPMN, messageExecution.getTenantId());

String messageName = EventDefinitionExpressionUtil.determineMessageName(commandContext, messageEventDefinition, definitionVariableContainer);
EventSubscriptionEntity messageSubscription = (EventSubscriptionEntity) eventSubscriptionService.createEventSubscriptionBuilder()
.eventType(MessageEventSubscriptionEntity.EVENT_TYPE)
.eventName(messageName)
Expand Down Expand Up @@ -1618,7 +1622,9 @@ protected void processCreatedEventSubProcess(EventSubProcess eventSubProcess, Ex
signalExecution.setEventScope(true);
signalExecution.setActive(false);

String eventName = EventDefinitionExpressionUtil.determineSignalName(commandContext, signalEventDefinition, bpmnModel, null);
DefinitionVariableContainer signalDefinitionVariableContainer = new DefinitionVariableContainer(signalExecution.getProcessDefinitionId(),
signalExecution.getProcessDefinitionKey(), eventSubProcessExecution.getDeploymentId(), ScopeTypes.BPMN, signalExecution.getTenantId());
String eventName = EventDefinitionExpressionUtil.determineSignalName(commandContext, signalEventDefinition, bpmnModel, signalDefinitionVariableContainer);

EventSubscriptionEntity signalSubscription = (EventSubscriptionEntity) eventSubscriptionService.createEventSubscriptionBuilder()
.eventType(SignalEventSubscriptionEntity.EVENT_TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import org.flowable.bpmn.model.Signal;
import org.flowable.bpmn.model.SignalEventDefinition;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.common.engine.api.scope.ScopeTypes;
import org.flowable.common.engine.api.variable.VariableContainer;
import org.flowable.common.engine.impl.el.DefinitionVariableContainer;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.variable.service.impl.el.NoExecutionVariableScope;

/**
Expand All @@ -34,7 +37,23 @@ public class EventDefinitionExpressionUtil {
* - otherwise, the signal ref is used
* - unless a signalExpression is set
*/
public static String determineSignalName(CommandContext commandContext, SignalEventDefinition signalEventDefinition, BpmnModel bpmnModel, DelegateExecution execution) {
public static String determineSignalName(CommandContext commandContext, SignalEventDefinition signalEventDefinition,
BpmnModel bpmnModel, ProcessDefinition processDefinition) {

DefinitionVariableContainer definitionVariableContainer = new DefinitionVariableContainer(processDefinition.getId(),
processDefinition.getKey(), processDefinition.getDeploymentId(), ScopeTypes.BPMN, processDefinition.getTenantId());

return determineSignalName(commandContext, signalEventDefinition, bpmnModel, definitionVariableContainer);
}

/**
* Determines the signal name of the {@link SignalEventDefinition} that is passed:
* - if a signal name is set, it has precedence
* - otherwise, the signal ref is used
* - unless a signalExpression is set
*/
public static String determineSignalName(CommandContext commandContext, SignalEventDefinition signalEventDefinition,
BpmnModel bpmnModel, VariableContainer variableContainer) {
String signalName = null;
if (StringUtils.isNotEmpty(signalEventDefinition.getSignalRef())) {
Signal signal = bpmnModel.getSignal(signalEventDefinition.getSignalRef());
Expand All @@ -51,12 +70,28 @@ public static String determineSignalName(CommandContext commandContext, SignalEv

if (StringUtils.isNotEmpty(signalName)) {
Expression expression = CommandContextUtil.getProcessEngineConfiguration(commandContext).getExpressionManager().createExpression(signalName);
return expression.getValue(execution != null ? execution : NoExecutionVariableScope.getSharedInstance()).toString();
return expression.getValue(variableContainer != null ? variableContainer : NoExecutionVariableScope.getSharedInstance()).toString();
}

return signalName;
}

/**
* Determines the event name of the {@link org.flowable.bpmn.model.MessageEventDefinition} that is passed:
* - if a message ref is set, it has precedence
* - if a messageExpression is set, it is returned
* <p>
* Note that, contrary to the determineSignalName method, the name of the message is never used.
* This is because of historical reasons (and it can't be changed now without breaking existing models/instances)
*/
public static String determineMessageName(CommandContext commandContext, MessageEventDefinition messageEventDefinition,
ProcessDefinition processDefinition) {

DefinitionVariableContainer definitionVariableContainer = new DefinitionVariableContainer(processDefinition.getId(),
processDefinition.getKey(), processDefinition.getDeploymentId(), ScopeTypes.BPMN, processDefinition.getTenantId());

return determineMessageName(commandContext, messageEventDefinition, definitionVariableContainer);
}
/**
* Determines the event name of the {@link org.flowable.bpmn.model.MessageEventDefinition} that is passed:
* - if a message ref is set, it has precedence
Expand All @@ -65,7 +100,8 @@ public static String determineSignalName(CommandContext commandContext, SignalEv
* Note that, contrary to the determineSignalName method, the name of the message is never used.
* This is because of historical reasons (and it can't be changed now without breaking existing models/instances)
*/
public static String determineMessageName(CommandContext commandContext, MessageEventDefinition messageEventDefinition, DelegateExecution execution) {
public static String determineMessageName(CommandContext commandContext, MessageEventDefinition messageEventDefinition,
VariableContainer variableContainer) {
String messageName = null;
if (StringUtils.isNotEmpty(messageEventDefinition.getMessageRef())) {
return messageEventDefinition.getMessageRef();
Expand All @@ -77,10 +113,9 @@ public static String determineMessageName(CommandContext commandContext, Message

if (StringUtils.isNotEmpty(messageName)) {
Expression expression = CommandContextUtil.getProcessEngineConfiguration(commandContext).getExpressionManager().createExpression(messageName);
return expression.getValue(execution != null ? execution : NoExecutionVariableScope.getSharedInstance()).toString();
return expression.getValue(variableContainer != null ? variableContainer : NoExecutionVariableScope.getSharedInstance()).toString();
}

return messageName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.common.engine.api.scope.ScopeTypes;
import org.flowable.common.engine.impl.el.DefinitionVariableContainer;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.util.CollectionUtil;
import org.flowable.engine.ProcessEngineConfiguration;
Expand All @@ -36,6 +37,7 @@
import org.flowable.engine.impl.event.EventDefinitionExpressionUtil;
import org.flowable.engine.impl.jobexecutor.TimerEventHandler;
import org.flowable.engine.impl.jobexecutor.TimerStartEventJobHandler;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityManager;
import org.flowable.engine.impl.util.CorrelationUtil;
Expand Down Expand Up @@ -154,31 +156,20 @@ protected void restorePreviousStartEventsIfNeeded(ProcessDefinition processDefin

protected void restoreTimerStartEvent(ProcessDefinition previousProcessDefinition, StartEvent startEvent, EventDefinition eventDefinition) {
TimerEventDefinition timerEventDefinition = (TimerEventDefinition) eventDefinition;
TimerJobEntity timer = TimerUtil.createTimerEntityForTimerEventDefinition((TimerEventDefinition) eventDefinition, startEvent,
false, null, TimerStartEventJobHandler.TYPE, TimerEventHandler.createConfiguration(startEvent.getId(),
timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));

if (timer != null) {
TimerJobEntity timerJob = TimerUtil.createTimerEntityForTimerEventDefinition(timerEventDefinition, startEvent,
false, null, TimerStartEventJobHandler.TYPE, TimerEventHandler.createConfiguration(startEvent.getId(),
timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));

timerJob.setProcessDefinitionId(previousProcessDefinition.getId());

if (previousProcessDefinition.getTenantId() != null) {
timerJob.setTenantId(previousProcessDefinition.getTenantId());
}
TimerJobEntity timerJob = TimerUtil.createTimerEntityForTimerEventDefinition(timerEventDefinition, startEvent,
false, previousProcessDefinition, TimerStartEventJobHandler.TYPE, TimerEventHandler.createConfiguration(startEvent.getId(),
timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));

engineConfiguration.getJobServiceConfiguration().getTimerJobService().scheduleTimerJob(timerJob);
}
engineConfiguration.getJobServiceConfiguration().getTimerJobService().scheduleTimerJob(timerJob);
}

protected void restoreSignalStartEvent(ProcessDefinition previousProcessDefinition, BpmnModel bpmnModel, StartEvent startEvent, EventDefinition eventDefinition) {
CommandContext commandContext = Context.getCommandContext();
SignalEventDefinition signalEventDefinition = (SignalEventDefinition) eventDefinition;
SignalEventSubscriptionEntity subscriptionEntity = engineConfiguration.getEventSubscriptionServiceConfiguration().getEventSubscriptionService().createSignalEventSubscription();

String eventName = EventDefinitionExpressionUtil.determineSignalName(commandContext, signalEventDefinition, bpmnModel, null);
String eventName = EventDefinitionExpressionUtil.determineSignalName(commandContext, signalEventDefinition, bpmnModel, previousProcessDefinition);
subscriptionEntity.setEventName(eventName);
subscriptionEntity.setActivityId(startEvent.getId());
subscriptionEntity.setProcessDefinitionId(previousProcessDefinition.getId());
Expand All @@ -199,7 +190,7 @@ protected void restoreMessageStartEvent(ProcessDefinition previousProcessDefinit

CommandContext commandContext = Context.getCommandContext();
MessageEventSubscriptionEntity newSubscription = engineConfiguration.getEventSubscriptionServiceConfiguration().getEventSubscriptionService().createMessageEventSubscription();
String messageName = EventDefinitionExpressionUtil.determineMessageName(commandContext, messageEventDefinition, null);
String messageName = EventDefinitionExpressionUtil.determineMessageName(commandContext, messageEventDefinition, previousProcessDefinition);
newSubscription.setEventName(messageName);
newSubscription.setActivityId(startEvent.getId());
newSubscription.setConfiguration(previousProcessDefinition.getId());
Expand Down
Loading
Loading