diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteRelatedDataOfRemovedHistoricCaseInstancesCmd.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteRelatedDataOfRemovedHistoricCaseInstancesCmd.java index 1f267bd6065..78078c3a4e9 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteRelatedDataOfRemovedHistoricCaseInstancesCmd.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteRelatedDataOfRemovedHistoricCaseInstancesCmd.java @@ -17,6 +17,7 @@ import org.flowable.cmmn.engine.CmmnEngineConfiguration; import org.flowable.cmmn.engine.impl.util.CommandContextUtil; +import org.flowable.common.engine.impl.history.HistoryLevel; import org.flowable.common.engine.impl.interceptor.Command; import org.flowable.common.engine.impl.interceptor.CommandContext; import org.flowable.entitylink.api.history.HistoricEntityLinkService; @@ -44,8 +45,9 @@ public Object execute(CommandContext commandContext) { } } cmmnEngineConfiguration.getTaskServiceConfiguration().getHistoricTaskService().deleteHistoricTaskLogEntriesForNonExistingCaseInstances(); - cmmnEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesForNonExistingCaseInstances(); - + if (cmmnEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) { + cmmnEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesForNonExistingCaseInstances(); + } return null; } diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/CmmnHistoryConfigurationSettings.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/CmmnHistoryConfigurationSettings.java index c5eab5ca9df..09f8c28a9f2 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/CmmnHistoryConfigurationSettings.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/CmmnHistoryConfigurationSettings.java @@ -19,6 +19,7 @@ import org.flowable.entitylink.service.impl.persistence.entity.EntityLinkEntity; import org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity; import org.flowable.task.api.TaskInfo; +import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity; /** @@ -78,4 +79,8 @@ public interface CmmnHistoryConfigurationSettings { */ boolean isHistoryEnabledForEntityLink(EntityLinkEntity entityLink); + /** + * Returns whether variable history is enabled for the provided historic task instance. + */ + boolean isHistoryEnabledForVariables(HistoricTaskInstance historicTaskInstance); } diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/DefaultCmmnHistoryConfigurationSettings.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/DefaultCmmnHistoryConfigurationSettings.java index fa73c9b6cd3..20a3f497103 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/DefaultCmmnHistoryConfigurationSettings.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/DefaultCmmnHistoryConfigurationSettings.java @@ -29,6 +29,7 @@ import org.flowable.entitylink.service.impl.persistence.entity.EntityLinkEntity; import org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity; import org.flowable.task.api.TaskInfo; +import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.service.impl.persistence.entity.TaskEntity; import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity; import org.slf4j.Logger; @@ -248,6 +249,11 @@ public boolean isHistoryEnabledForEntityLink(EntityLinkEntity entityLink) { return isHistoryLevelAtLeast(HistoryLevel.AUDIT, caseDefinitionId); } + @Override + public boolean isHistoryEnabledForVariables(HistoricTaskInstance historicTaskInstance) { + return cmmnEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY); + } + protected String getCaseDefinitionId(EntityLinkEntity entityLink) { String caseDefinitionId = null; if (ScopeTypes.CMMN.equals(entityLink.getScopeType()) && entityLink.getScopeId() != null) { diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/task/TaskHelper.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/task/TaskHelper.java index 5caf68b0d8c..aa479df7597 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/task/TaskHelper.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/task/TaskHelper.java @@ -209,8 +209,11 @@ public static void deleteHistoricTask(String taskId, CmmnEngineConfiguration cmm for (HistoricTaskInstance subTask : subTasks) { deleteHistoricTask(subTask.getId(), cmmnEngineConfiguration); } - - cmmnEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByTaskId(taskId); + + if (cmmnEngineConfiguration.getCmmnHistoryConfigurationSettings().isHistoryEnabledForVariables(historicTaskInstance)) { + cmmnEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByTaskId(taskId); + } + cmmnEngineConfiguration.getIdentityLinkServiceConfiguration().getHistoricIdentityLinkService().deleteHistoricIdentityLinksByTaskId(taskId); historicTaskService.deleteHistoricTask(historicTaskInstance); diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteRelatedDataOfRemovedHistoricProcessInstancesCmd.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteRelatedDataOfRemovedHistoricProcessInstancesCmd.java index e436864023a..39759d402fc 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteRelatedDataOfRemovedHistoricProcessInstancesCmd.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteRelatedDataOfRemovedHistoricProcessInstancesCmd.java @@ -15,6 +15,7 @@ import java.io.Serializable; +import org.flowable.common.engine.impl.history.HistoryLevel; import org.flowable.common.engine.impl.interceptor.Command; import org.flowable.common.engine.impl.interceptor.CommandContext; import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl; @@ -38,7 +39,10 @@ public Object execute(CommandContext commandContext) { } } processEngineConfiguration.getTaskServiceConfiguration().getHistoricTaskService().deleteHistoricTaskLogEntriesForNonExistingProcessInstances(); - processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesForNonExistingProcessInstances(); + if (processEngineConfiguration.getHistoryManager().isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { + processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService() + .deleteHistoricVariableInstancesForNonExistingProcessInstances(); + } processEngineConfiguration.getHistoricDetailEntityManager().deleteHistoricDetailForNonExistingProcessInstances(); return null; diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/DefaultHistoryConfigurationSettings.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/DefaultHistoryConfigurationSettings.java index 23f6da8f5a0..a6faa53ed47 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/DefaultHistoryConfigurationSettings.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/DefaultHistoryConfigurationSettings.java @@ -19,6 +19,7 @@ import org.flowable.bpmn.model.Process; import org.flowable.common.engine.api.scope.ScopeTypes; import org.flowable.common.engine.impl.history.HistoryLevel; +import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl; import org.flowable.engine.impl.persistence.entity.ExecutionEntity; import org.flowable.engine.impl.util.ProcessDefinitionUtil; @@ -27,6 +28,7 @@ import org.flowable.entitylink.service.impl.persistence.entity.EntityLinkEntity; import org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity; import org.flowable.task.api.TaskInfo; +import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.service.impl.persistence.entity.TaskEntity; import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity; import org.slf4j.Logger; @@ -281,6 +283,11 @@ public boolean isHistoryEnabledForVariableInstance(String processDefinitionId, V return isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processDefinitionId); } + @Override + public boolean isHistoryEnabledForVariables(HistoricProcessInstance historicProcessInstance) { + return processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY); + } + @Override public boolean isHistoryEnabledForIdentityLink(IdentityLinkEntity identityLink) { String processDefinitionId = getProcessDefinitionId(identityLink); @@ -309,6 +316,11 @@ public boolean isHistoryEnabledForEntityLink(EntityLinkEntity entityLink) { return isHistoryLevelAtLeast(HistoryLevel.AUDIT, processDefinitionId); } + @Override + public boolean isHistoryEnabledForVariables(HistoricTaskInstance historicTaskInstance) { + return processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY); + } + protected String getProcessDefinitionId(EntityLinkEntity entityLink) { String processDefinitionId = null; if (ScopeTypes.BPMN.equals(entityLink.getScopeType()) && entityLink.getScopeId() != null) { diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/DefaultHistoryManager.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/DefaultHistoryManager.java index ec0e67bf362..c6b6b9df43e 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/DefaultHistoryManager.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/DefaultHistoryManager.java @@ -129,7 +129,9 @@ public void recordProcessInstanceDeleted(String processInstanceId, String proces HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().findById(processInstanceId); getHistoricDetailEntityManager().deleteHistoricDetailsByProcessInstanceId(processInstanceId); - processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByProcessInstanceId(processInstanceId); + if (getHistoryConfigurationSettings().isHistoryEnabledForVariables(historicProcessInstance)) { + processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByProcessInstanceId(processInstanceId); + } getHistoricActivityInstanceEntityManager().deleteHistoricActivityInstancesByProcessInstanceId(processInstanceId); TaskHelper.deleteHistoricTaskInstancesByProcessInstanceId(processInstanceId); processEngineConfiguration.getIdentityLinkServiceConfiguration().getHistoricIdentityLinkService().deleteHistoricIdentityLinksByProcessInstanceId(processInstanceId); diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/HistoryConfigurationSettings.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/HistoryConfigurationSettings.java index 576fcc1ba6b..d8bf38015e8 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/HistoryConfigurationSettings.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/HistoryConfigurationSettings.java @@ -13,11 +13,13 @@ package org.flowable.engine.impl.history; import org.flowable.common.engine.impl.history.HistoryLevel; +import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.impl.persistence.entity.ExecutionEntity; import org.flowable.engine.runtime.ActivityInstance; import org.flowable.entitylink.service.impl.persistence.entity.EntityLinkEntity; import org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity; import org.flowable.task.api.TaskInfo; +import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.service.impl.persistence.entity.TaskEntity; import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity; @@ -81,6 +83,16 @@ public interface HistoryConfigurationSettings { */ boolean isHistoryEnabledForVariableInstance(String processDefinitionId, VariableInstanceEntity variableInstanceEntity); + /** + * Returns whether history is enabled for variables for the provided historic process instance. + */ + boolean isHistoryEnabledForVariables(HistoricProcessInstance historicProcessInstance); + + /** + * Returns whether variable history is enabled for the provided historic task instance. + */ + boolean isHistoryEnabledForVariables(HistoricTaskInstance historicTaskInstance); + /** * Returns whether history is enabled for the provided identity link. */ @@ -90,5 +102,4 @@ public interface HistoryConfigurationSettings { * Returns whether history is enabled for the provided entity link. */ boolean isHistoryEnabledForEntityLink(EntityLinkEntity entityLink); - } diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/util/TaskHelper.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/util/TaskHelper.java index 6d444f774b9..9a5e33f65e3 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/util/TaskHelper.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/util/TaskHelper.java @@ -578,7 +578,9 @@ public static void deleteHistoricTask(String taskId) { } processEngineConfiguration.getHistoricDetailEntityManager().deleteHistoricDetailsByTaskId(taskId); - processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByTaskId(taskId); + if (processEngineConfiguration.getHistoryConfigurationSettings().isHistoryEnabledForVariables(historicTaskInstance)) { + processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByTaskId(taskId); + } processEngineConfiguration.getIdentityLinkServiceConfiguration().getHistoricIdentityLinkService().deleteHistoricIdentityLinksByTaskId(taskId); historicTaskService.deleteHistoricTask(historicTaskInstance); diff --git a/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/persistence/entity/HistoricVariableInstanceEntityManagerImpl.java b/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/persistence/entity/HistoricVariableInstanceEntityManagerImpl.java index 17fcb8e1dd9..29c17d35d0b 100644 --- a/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/persistence/entity/HistoricVariableInstanceEntityManagerImpl.java +++ b/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/persistence/entity/HistoricVariableInstanceEntityManagerImpl.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.Map; -import org.flowable.common.engine.impl.history.HistoryLevel; import org.flowable.common.engine.impl.persistence.entity.AbstractServiceEngineEntityManager; import org.flowable.variable.api.history.HistoricVariableInstance; import org.flowable.variable.service.VariableServiceConfiguration; @@ -101,11 +100,9 @@ public void delete(HistoricVariableInstanceEntity entity, boolean fireDeleteEven @Override public void deleteHistoricVariableInstanceByProcessInstanceId(final String historicProcessInstanceId) { - if (serviceConfiguration.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { - List historicProcessVariables = dataManager.findHistoricVariableInstancesByProcessInstanceId(historicProcessInstanceId); - for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) { - delete(historicProcessVariable); - } + List historicProcessVariables = dataManager.findHistoricVariableInstancesByProcessInstanceId(historicProcessInstanceId); + for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) { + delete(historicProcessVariable); } } @@ -146,11 +143,9 @@ public List findHistoricalVariableInstancesBySub @Override public void deleteHistoricVariableInstancesByTaskId(String taskId) { - if (serviceConfiguration.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { - List historicProcessVariables = dataManager.findHistoricVariableInstancesByTaskId(taskId); - for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) { - delete(historicProcessVariable); - } + List historicProcessVariables = dataManager.findHistoricVariableInstancesByTaskId(taskId); + for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) { + delete(historicProcessVariable); } } @@ -171,16 +166,12 @@ public void bulkDeleteHistoricVariableInstancesByScopeIdsAndScopeType(Collection @Override public void deleteHistoricVariableInstancesForNonExistingProcessInstances() { - if (serviceConfiguration.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { - dataManager.deleteHistoricVariableInstancesForNonExistingProcessInstances(); - } + dataManager.deleteHistoricVariableInstancesForNonExistingProcessInstances(); } @Override public void deleteHistoricVariableInstancesForNonExistingCaseInstances() { - if (serviceConfiguration.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { - dataManager.deleteHistoricVariableInstancesForNonExistingCaseInstances(); - } + dataManager.deleteHistoricVariableInstancesForNonExistingCaseInstances(); } @Override