Skip to content

Commit

Permalink
Move history check for variable deletion to history manager (#3823)
Browse files Browse the repository at this point in the history
Use new methods in `HistoryConfigurationSettings` and `CmmnHistoryConfigurationSettings`
to check if variables should be deleted for a process / task isntance
  • Loading branch information
WelschChristopher authored Jan 25, 2024
1 parent 81c0f87 commit e578616
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
*/
Expand All @@ -90,5 +102,4 @@ public interface HistoryConfigurationSettings {
* Returns whether history is enabled for the provided entity link.
*/
boolean isHistoryEnabledForEntityLink(EntityLinkEntity entityLink);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,11 +100,9 @@ public void delete(HistoricVariableInstanceEntity entity, boolean fireDeleteEven

@Override
public void deleteHistoricVariableInstanceByProcessInstanceId(final String historicProcessInstanceId) {
if (serviceConfiguration.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
List<HistoricVariableInstanceEntity> historicProcessVariables = dataManager.findHistoricVariableInstancesByProcessInstanceId(historicProcessInstanceId);
for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) {
delete(historicProcessVariable);
}
List<HistoricVariableInstanceEntity> historicProcessVariables = dataManager.findHistoricVariableInstancesByProcessInstanceId(historicProcessInstanceId);
for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) {
delete(historicProcessVariable);
}
}

Expand Down Expand Up @@ -146,11 +143,9 @@ public List<HistoricVariableInstanceEntity> findHistoricalVariableInstancesBySub

@Override
public void deleteHistoricVariableInstancesByTaskId(String taskId) {
if (serviceConfiguration.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
List<HistoricVariableInstanceEntity> historicProcessVariables = dataManager.findHistoricVariableInstancesByTaskId(taskId);
for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) {
delete(historicProcessVariable);
}
List<HistoricVariableInstanceEntity> historicProcessVariables = dataManager.findHistoricVariableInstancesByTaskId(taskId);
for (HistoricVariableInstanceEntity historicProcessVariable : historicProcessVariables) {
delete(historicProcessVariable);
}
}

Expand All @@ -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
Expand Down

0 comments on commit e578616

Please sign in to comment.