Skip to content
Merged
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
Expand Up @@ -15,16 +15,13 @@
import java.io.Serializable;

import org.flowable.cmmn.api.runtime.CaseInstance;
import org.flowable.cmmn.engine.impl.event.FlowableCmmnEventBuilder;
import org.flowable.cmmn.engine.impl.persistence.entity.CaseInstanceEntity;
import org.flowable.cmmn.engine.impl.persistence.entity.CaseInstanceEntityManager;
import org.flowable.cmmn.engine.impl.util.CommandContextUtil;
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.interceptor.EngineConfigurationConstants;

public class SetCaseInstanceBusinessStatusCmd implements Command<Void>, Serializable {

Expand All @@ -50,14 +47,8 @@ public Void execute(CommandContext commandContext) {
throw new FlowableObjectNotFoundException("No case instance found for id = '" + caseInstanceId + "'.", CaseInstance.class);
}

String oldBusinessStatus = caseInstanceEntity.getBusinessStatus();
caseInstanceEntityManager.updateCaseInstanceBusinessStatus(caseInstanceEntity, businessStatus);

FlowableEventDispatcher eventDispatcher = CommandContextUtil.getEventDispatcher(commandContext);
if (eventDispatcher != null && eventDispatcher.isEnabled()) {
eventDispatcher.dispatchEvent(FlowableCmmnEventBuilder.createCaseBusinessStatusUpdatedEvent(caseInstanceEntity, oldBusinessStatus, businessStatus), EngineConfigurationConstants.KEY_CMMN_ENGINE_CONFIG);
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
import org.flowable.cmmn.api.runtime.PlanItemInstanceState;
import org.flowable.cmmn.engine.CmmnEngineConfiguration;
import org.flowable.cmmn.engine.impl.behavior.impl.ChildTaskActivityBehavior;
import org.flowable.cmmn.engine.impl.event.FlowableCmmnEventBuilder;
import org.flowable.cmmn.engine.impl.persistence.entity.data.CaseInstanceDataManager;
import org.flowable.cmmn.engine.impl.runtime.CaseInstanceQueryImpl;
import org.flowable.cmmn.engine.impl.task.TaskHelper;
import org.flowable.cmmn.engine.impl.util.CommandContextUtil;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.common.engine.api.scope.ScopeTypes;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.persistence.entity.AbstractEngineEntityManager;
Expand Down Expand Up @@ -263,8 +265,16 @@ public void updateCaseInstanceBusinessKey(CaseInstanceEntity caseInstanceEntity,
@Override
public void updateCaseInstanceBusinessStatus(CaseInstanceEntity caseInstanceEntity, String businessStatus) {
if (businessStatus != null) {
String oldBusinessStatus = caseInstanceEntity.getBusinessStatus();
caseInstanceEntity.setBusinessStatus(businessStatus);
engineConfiguration.getCmmnHistoryManager().recordUpdateBusinessStatus(caseInstanceEntity, businessStatus);

FlowableEventDispatcher eventDispatcher = getEventDispatcher();
if (eventDispatcher != null && eventDispatcher.isEnabled()) {
eventDispatcher.dispatchEvent(
FlowableCmmnEventBuilder.createCaseBusinessStatusUpdatedEvent(caseInstanceEntity, oldBusinessStatus, businessStatus),
engineConfiguration.getEngineCfgKey());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,51 @@ public void testBusinessStatusUpdatedEvent() {
assertThat(events).hasSize(1);
}

@Test
@CmmnDeployment(resources = "org/flowable/cmmn/test/runtime/oneTaskCase.cmmn")
public void testBusinessStatusUpdatedEventWithUpdateBuilder() {
List<FlowableEvent> events = new ArrayList<>();
businessStatusUpdatedEventListener.eventConsumer = (flowableEvent) -> {
if (flowableEvent instanceof FlowableCaseBusinessStatusUpdatedEvent caseBusinessStatusUpdatedEvent) {
CaseInstance eventCaseInstance = (CaseInstance) caseBusinessStatusUpdatedEvent.getEntity();
assertThat(caseBusinessStatusUpdatedEvent.getScopeType()).isEqualTo(ScopeTypes.CMMN);
assertThat(caseBusinessStatusUpdatedEvent.getScopeId()).isNotNull().isEqualTo(eventCaseInstance.getId());
assertThat(caseBusinessStatusUpdatedEvent.getOldBusinessStatus()).isEqualTo("oldStatus");
assertThat(caseBusinessStatusUpdatedEvent.getNewBusinessStatus()).isEqualTo("newStatus");
events.add(flowableEvent);
}
};

CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
.caseDefinitionKey("oneTaskCase")
.businessStatus("oldStatus")
.start();

cmmnRuntimeService.createCaseInstanceUpdateBuilder(caseInstance.getId())
.businessStatus("newStatus")
.update();

assertThat(events).hasSize(1);
}

@Test
@CmmnDeployment(resources = "org/flowable/cmmn/test/runtime/oneTaskCase.cmmn")
public void testNoBusinessStatusUpdatedEventWhenUpdateBuilderDoesNotSetBusinessStatus() {
List<FlowableEvent> events = new ArrayList<>();
businessStatusUpdatedEventListener.eventConsumer = events::add;

CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
.caseDefinitionKey("oneTaskCase")
.businessStatus("oldStatus")
.start();

cmmnRuntimeService.createCaseInstanceUpdateBuilder(caseInstance.getId())
.name("newName")
.update();

assertThat(events).isEmpty();
}

public static class CustomEventListener extends AbstractFlowableEventListener {

private Consumer<FlowableEvent> eventConsumer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@

import org.flowable.common.engine.api.FlowableIllegalArgumentException;
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.interceptor.EngineConfigurationConstants;
import org.flowable.engine.delegate.event.impl.FlowableEventBuilder;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityManager;
import org.flowable.engine.impl.util.CommandContextUtil;
Expand Down Expand Up @@ -64,13 +61,8 @@ public Void execute(CommandContext commandContext) {
+ processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
}

String oldBusinessStatus = processInstance.getBusinessStatus();
executionManager.updateProcessInstanceBusinessStatus(processInstance, businessStatus);

FlowableEventDispatcher eventDispatcher = CommandContextUtil.getEventDispatcher(commandContext);
if (eventDispatcher != null && eventDispatcher.isEnabled()) {
eventDispatcher.dispatchEvent(FlowableEventBuilder.createProcessBusinessStatusUpdatedEvent(processInstance, oldBusinessStatus, businessStatus), EngineConfigurationConstants.KEY_PROCESS_ENGINE_CONFIG);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1114,11 +1114,16 @@ public String updateProcessInstanceBusinessKey(ExecutionEntity executionEntity,
@Override
public String updateProcessInstanceBusinessStatus(ExecutionEntity executionEntity, String businessStatus) {
if (executionEntity.isProcessInstanceType() && businessStatus != null) {
String oldBusinessStatus = executionEntity.getBusinessStatus();
executionEntity.setBusinessStatus(businessStatus);
getHistoryManager().updateProcessBusinessStatusInHistory(executionEntity);

if (getEventDispatcher() != null && getEventDispatcher().isEnabled()) {
getEventDispatcher().dispatchEvent(FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, executionEntity),
FlowableEventDispatcher eventDispatcher = getEventDispatcher();
if (eventDispatcher != null && eventDispatcher.isEnabled()) {
eventDispatcher.dispatchEvent(FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, executionEntity),
engineConfiguration.getEngineCfgKey());
eventDispatcher.dispatchEvent(
FlowableEventBuilder.createProcessBusinessStatusUpdatedEvent(executionEntity, oldBusinessStatus, businessStatus),
engineConfiguration.getEngineCfgKey());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,51 @@ public void testBusinessStatusUpdatedEvent() {
assertThat(events).hasSize(1);
}

@Test
@Deployment(resources = "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml")
public void testBusinessStatusUpdatedEventWithUpdateBuilder() {
List<FlowableEvent> events = new ArrayList<>();
businessStatusUpdatedEventListener.eventConsumer = (flowableEvent) -> {
if (flowableEvent instanceof FlowableProcessBusinessStatusUpdatedEvent processBusinessStatusUpdatedEvent) {
Execution execution = (Execution) processBusinessStatusUpdatedEvent.getEntity();
assertThat(processBusinessStatusUpdatedEvent.getScopeType()).isEqualTo(ScopeTypes.BPMN);
assertThat(processBusinessStatusUpdatedEvent.getScopeId()).isNotNull().isEqualTo(execution.getId());
assertThat(processBusinessStatusUpdatedEvent.getOldBusinessStatus()).isEqualTo("oldStatus");
assertThat(processBusinessStatusUpdatedEvent.getNewBusinessStatus()).isEqualTo("newStatus");
events.add(flowableEvent);
}
};

ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey("oneTaskProcess")
.businessStatus("oldStatus")
.start();

runtimeService.createProcessInstanceUpdateBuilder(processInstance.getId())
.businessStatus("newStatus")
.update();

assertThat(events).hasSize(1);
}

@Test
@Deployment(resources = "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml")
public void testNoBusinessStatusUpdatedEventWhenUpdateBuilderDoesNotSetBusinessStatus() {
List<FlowableEvent> events = new ArrayList<>();
businessStatusUpdatedEventListener.eventConsumer = events::add;

ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey("oneTaskProcess")
.businessStatus("oldStatus")
.start();

runtimeService.createProcessInstanceUpdateBuilder(processInstance.getId())
.name("newName")
.update();

assertThat(events).isEmpty();
}

public static class CustomEventListener extends AbstractFlowableEventListener {

private Consumer<FlowableEvent> eventConsumer;
Expand Down
Loading