From 13fb371309e60da9fe982de8c8fab3e062d23fad Mon Sep 17 00:00:00 2001 From: Christopher Welsch Date: Thu, 18 Jan 2024 09:54:42 +0100 Subject: [PATCH 1/4] moved the history level check into out of the HistoricVariableInstanceEntityManangerImpl and into the classes that called the methods. --- ...eRelatedDataOfRemovedHistoricCaseInstancesCmd.java | 6 ++++-- .../flowable/cmmn/engine/impl/task/TaskHelper.java | 6 ++++-- ...latedDataOfRemovedHistoricProcessInstancesCmd.java | 5 ++++- .../engine/impl/history/DefaultHistoryManager.java | 4 +++- .../org/flowable/engine/impl/util/TaskHelper.java | 4 +++- .../test/api/history/ChangeHistoryLevelTest.java | 5 ++++- .../HistoricVariableInstanceEntityManagerImpl.java | 11 +---------- 7 files changed, 23 insertions(+), 18 deletions(-) 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/task/TaskHelper.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/task/TaskHelper.java index 5caf68b0d8c..eff7e61e073 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,10 @@ public static void deleteHistoricTask(String taskId, CmmnEngineConfiguration cmm for (HistoricTaskInstance subTask : subTasks) { deleteHistoricTask(subTask.getId(), cmmnEngineConfiguration); } - - cmmnEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByTaskId(taskId); + + if (cmmnEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) { + 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..a71c528e7b4 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,9 @@ 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/DefaultHistoryManager.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/DefaultHistoryManager.java index ec0e67bf362..185ab57ef45 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 (processEngineConfiguration.getHistoryManager().isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { + 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/util/TaskHelper.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/util/TaskHelper.java index 6d444f774b9..2677dbdd049 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.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) { + processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByTaskId(taskId); + } processEngineConfiguration.getIdentityLinkServiceConfiguration().getHistoricIdentityLinkService().deleteHistoricIdentityLinksByTaskId(taskId); historicTaskService.deleteHistoricTask(historicTaskInstance); diff --git a/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/history/ChangeHistoryLevelTest.java b/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/history/ChangeHistoryLevelTest.java index 546d7c7dba2..153c6c247fb 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/history/ChangeHistoryLevelTest.java +++ b/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/history/ChangeHistoryLevelTest.java @@ -129,7 +129,10 @@ protected void deleteHistoricData(String processInstanceId, String taskId) { @Override public Void execute(CommandContext commandContext) { processEngineConfiguration.getHistoricDetailEntityManager().deleteHistoricDetailsByProcessInstanceId(processInstanceId); - processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByProcessInstanceId(processInstanceId); + + if (processEngineConfiguration.getHistoryManager().isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { + processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByProcessInstanceId(processInstanceId); + } processEngineConfiguration.getIdentityLinkServiceConfiguration().getHistoricIdentityLinkService().deleteHistoricIdentityLinksByProcessInstanceId(processInstanceId); if (taskId != null) { 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..5e0811fd86f 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,12 +100,10 @@ public void delete(HistoricVariableInstanceEntity entity, boolean fireDeleteEven @Override public void deleteHistoricVariableInstanceByProcessInstanceId(final String historicProcessInstanceId) { - if (serviceConfiguration.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { - List historicProcessVariables = dataManager.findHistoricVariableInstancesByProcessInstanceId(historicProcessInstanceId); + List historicProcessVariables = dataManager.findHistoricVariableInstancesByProcessInstanceId(historicProcessInstanceId); for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) { delete(historicProcessVariable); } - } } @Override @@ -146,12 +143,10 @@ 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); } - } } @Override @@ -171,16 +166,12 @@ public void bulkDeleteHistoricVariableInstancesByScopeIdsAndScopeType(Collection @Override public void deleteHistoricVariableInstancesForNonExistingProcessInstances() { - if (serviceConfiguration.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { dataManager.deleteHistoricVariableInstancesForNonExistingProcessInstances(); - } } @Override public void deleteHistoricVariableInstancesForNonExistingCaseInstances() { - if (serviceConfiguration.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { dataManager.deleteHistoricVariableInstancesForNonExistingCaseInstances(); - } } @Override From 8980e9c9a44cf69c6a6716e4b1fc61fd992ce676 Mon Sep 17 00:00:00 2001 From: Christopher Welsch Date: Thu, 18 Jan 2024 13:41:12 +0100 Subject: [PATCH 2/4] fixed formatting --- ...taOfRemovedHistoricProcessInstancesCmd.java | 5 +++-- ...toricVariableInstanceEntityManagerImpl.java | 18 +++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) 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 a71c528e7b4..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 @@ -39,8 +39,9 @@ public Object execute(CommandContext commandContext) { } } processEngineConfiguration.getTaskServiceConfiguration().getHistoricTaskService().deleteHistoricTaskLogEntriesForNonExistingProcessInstances(); - if(processEngineConfiguration.getHistoryManager().isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)){ - processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesForNonExistingProcessInstances(); + if (processEngineConfiguration.getHistoryManager().isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { + processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService() + .deleteHistoricVariableInstancesForNonExistingProcessInstances(); } processEngineConfiguration.getHistoricDetailEntityManager().deleteHistoricDetailForNonExistingProcessInstances(); 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 5e0811fd86f..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 @@ -101,9 +101,9 @@ public void delete(HistoricVariableInstanceEntity entity, boolean fireDeleteEven @Override public void deleteHistoricVariableInstanceByProcessInstanceId(final String historicProcessInstanceId) { List historicProcessVariables = dataManager.findHistoricVariableInstancesByProcessInstanceId(historicProcessInstanceId); - for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) { - delete(historicProcessVariable); - } + for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) { + delete(historicProcessVariable); + } } @Override @@ -143,10 +143,10 @@ public List findHistoricalVariableInstancesBySub @Override public void deleteHistoricVariableInstancesByTaskId(String taskId) { - List historicProcessVariables = dataManager.findHistoricVariableInstancesByTaskId(taskId); - for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) { - delete(historicProcessVariable); - } + List historicProcessVariables = dataManager.findHistoricVariableInstancesByTaskId(taskId); + for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) { + delete(historicProcessVariable); + } } @Override @@ -166,12 +166,12 @@ public void bulkDeleteHistoricVariableInstancesByScopeIdsAndScopeType(Collection @Override public void deleteHistoricVariableInstancesForNonExistingProcessInstances() { - dataManager.deleteHistoricVariableInstancesForNonExistingProcessInstances(); + dataManager.deleteHistoricVariableInstancesForNonExistingProcessInstances(); } @Override public void deleteHistoricVariableInstancesForNonExistingCaseInstances() { - dataManager.deleteHistoricVariableInstancesForNonExistingCaseInstances(); + dataManager.deleteHistoricVariableInstancesForNonExistingCaseInstances(); } @Override From c2b094ef4e38d59f49bf435f1dc7480cb63f51a5 Mon Sep 17 00:00:00 2001 From: Christopher Welsch Date: Thu, 18 Jan 2024 16:20:47 +0100 Subject: [PATCH 3/4] added new method to check if isHistoryEnabledForVariables --- .../impl/history/DefaultHistoryConfigurationSettings.java | 6 ++++++ .../flowable/engine/impl/history/DefaultHistoryManager.java | 2 +- .../engine/impl/history/HistoryConfigurationSettings.java | 6 ++++++ .../engine/test/api/history/ChangeHistoryLevelTest.java | 5 +---- 4 files changed, 14 insertions(+), 5 deletions(-) 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..36e140e664f 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 @@ -21,6 +21,7 @@ import org.flowable.common.engine.impl.history.HistoryLevel; import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl; import org.flowable.engine.impl.persistence.entity.ExecutionEntity; +import org.flowable.engine.impl.persistence.entity.HistoricProcessInstanceEntity; import org.flowable.engine.impl.util.ProcessDefinitionUtil; import org.flowable.engine.repository.ProcessDefinition; import org.flowable.engine.runtime.ActivityInstance; @@ -281,6 +282,11 @@ public boolean isHistoryEnabledForVariableInstance(String processDefinitionId, V return isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processDefinitionId); } + @Override + public boolean isHistoryEnabledForVariables(HistoricProcessInstanceEntity historicProcessInstance) { + return processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY); + } + @Override public boolean isHistoryEnabledForIdentityLink(IdentityLinkEntity identityLink) { String processDefinitionId = getProcessDefinitionId(identityLink); 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 185ab57ef45..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,7 @@ public void recordProcessInstanceDeleted(String processInstanceId, String proces HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().findById(processInstanceId); getHistoricDetailEntityManager().deleteHistoricDetailsByProcessInstanceId(processInstanceId); - if (processEngineConfiguration.getHistoryManager().isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { + if (getHistoryConfigurationSettings().isHistoryEnabledForVariables(historicProcessInstance)) { processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByProcessInstanceId(processInstanceId); } getHistoricActivityInstanceEntityManager().deleteHistoricActivityInstancesByProcessInstanceId(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..c483f223ecd 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 @@ -14,6 +14,7 @@ import org.flowable.common.engine.impl.history.HistoryLevel; import org.flowable.engine.impl.persistence.entity.ExecutionEntity; +import org.flowable.engine.impl.persistence.entity.HistoricProcessInstanceEntity; import org.flowable.engine.runtime.ActivityInstance; import org.flowable.entitylink.service.impl.persistence.entity.EntityLinkEntity; import org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity; @@ -81,6 +82,11 @@ public interface HistoryConfigurationSettings { */ boolean isHistoryEnabledForVariableInstance(String processDefinitionId, VariableInstanceEntity variableInstanceEntity); + /** + * Returns whether history is enabled for variables for the provided historic process instance. + */ + boolean isHistoryEnabledForVariables(HistoricProcessInstanceEntity historicProcessInstance); + /** * Returns whether history is enabled for the provided identity link. */ diff --git a/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/history/ChangeHistoryLevelTest.java b/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/history/ChangeHistoryLevelTest.java index 153c6c247fb..546d7c7dba2 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/history/ChangeHistoryLevelTest.java +++ b/modules/flowable-engine/src/test/java/org/flowable/engine/test/api/history/ChangeHistoryLevelTest.java @@ -129,10 +129,7 @@ protected void deleteHistoricData(String processInstanceId, String taskId) { @Override public Void execute(CommandContext commandContext) { processEngineConfiguration.getHistoricDetailEntityManager().deleteHistoricDetailsByProcessInstanceId(processInstanceId); - - if (processEngineConfiguration.getHistoryManager().isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) { - processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByProcessInstanceId(processInstanceId); - } + processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByProcessInstanceId(processInstanceId); processEngineConfiguration.getIdentityLinkServiceConfiguration().getHistoricIdentityLinkService().deleteHistoricIdentityLinksByProcessInstanceId(processInstanceId); if (taskId != null) { From ef62328f540c3487067fe0e0a858fe91dd6b94de Mon Sep 17 00:00:00 2001 From: Christopher Welsch Date: Wed, 24 Jan 2024 15:10:48 +0100 Subject: [PATCH 4/4] added method to check history level of historic task instances --- .../history/CmmnHistoryConfigurationSettings.java | 5 +++++ .../DefaultCmmnHistoryConfigurationSettings.java | 6 ++++++ .../flowable/cmmn/engine/impl/task/TaskHelper.java | 3 ++- .../history/DefaultHistoryConfigurationSettings.java | 10 ++++++++-- .../impl/history/HistoryConfigurationSettings.java | 11 ++++++++--- .../org/flowable/engine/impl/util/TaskHelper.java | 2 +- 6 files changed, 30 insertions(+), 7 deletions(-) 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 eff7e61e073..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 @@ -210,9 +210,10 @@ public static void deleteHistoricTask(String taskId, CmmnEngineConfiguration cmm deleteHistoricTask(subTask.getId(), cmmnEngineConfiguration); } - if (cmmnEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) { + 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/history/DefaultHistoryConfigurationSettings.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/DefaultHistoryConfigurationSettings.java index 36e140e664f..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,15 +19,16 @@ 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.persistence.entity.HistoricProcessInstanceEntity; import org.flowable.engine.impl.util.ProcessDefinitionUtil; import org.flowable.engine.repository.ProcessDefinition; 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; import org.slf4j.Logger; @@ -283,7 +284,7 @@ public boolean isHistoryEnabledForVariableInstance(String processDefinitionId, V } @Override - public boolean isHistoryEnabledForVariables(HistoricProcessInstanceEntity historicProcessInstance) { + public boolean isHistoryEnabledForVariables(HistoricProcessInstance historicProcessInstance) { return processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY); } @@ -315,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/HistoryConfigurationSettings.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/history/HistoryConfigurationSettings.java index c483f223ecd..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,12 +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.impl.persistence.entity.HistoricProcessInstanceEntity; 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; @@ -85,7 +86,12 @@ public interface HistoryConfigurationSettings { /** * Returns whether history is enabled for variables for the provided historic process instance. */ - boolean isHistoryEnabledForVariables(HistoricProcessInstanceEntity historicProcessInstance); + 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. @@ -96,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 2677dbdd049..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,7 @@ public static void deleteHistoricTask(String taskId) { } processEngineConfiguration.getHistoricDetailEntityManager().deleteHistoricDetailsByTaskId(taskId); - if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) { + if (processEngineConfiguration.getHistoryConfigurationSettings().isHistoryEnabledForVariables(historicTaskInstance)) { processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService().deleteHistoricVariableInstancesByTaskId(taskId); } processEngineConfiguration.getIdentityLinkServiceConfiguration().getHistoricIdentityLinkService().deleteHistoricIdentityLinksByTaskId(taskId);