Source:
public Void execute(Context context) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class)); if (caseFiles.size() != 1) { throw new IllegalStateException("Not able to find distinct case file - found case files " + caseFiles.size()); } CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next(); authorizationManager.checkDataAuthorization(caseFile.getCaseId(), caseFile, variableNames); org.jbpm.process.instance.ProcessInstance pi = (org.jbpm.process.instance.ProcessInstance) ksession.getProcessInstance(processInstanceId); VariableScope variableScope = (VariableScope) pi.getContextContainer().getDefaultContext(VariableScope.VARIABLE_SCOPE); for (String name: variableNames) { if (caseFile.getData(name) != null && variableScope.isReadOnly(VariableScope.CASE_FILE_PREFIX+name)) { throw new VariableViolationException(pi.getId(), name,"variable is read only and cannot be removed"); } } FactHandle factHandle = ksession.getFactHandle(caseFile); Map<String, Object> remove = new HashMap<>(); variableNames.forEach(p -> remove.put(p, caseFile.getData(p))); CaseEventSupport caseEventSupport = getCaseEventSupport(context); caseEventSupport.fireBeforeCaseDataRemoved(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), remove); variableNames.forEach(p -> caseFile.remove(p)); ksession.update(factHandle, caseFile); triggerRules(ksession); caseEventSupport.fireAfterCaseDataRemoved(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), remove); return null; }

Target:
public Void execute(Context context) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class)); if (caseFiles.size() != 1) { throw new IllegalStateException("Not able to find distinct case file - found case files " + caseFiles.size()); } CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next(); authorizationManager.checkDataAuthorization(caseFile.getCaseId(), caseFile, variableNames); org.jbpm.process.instance.ProcessInstance pi = (org.jbpm.process.instance.ProcessInstance) ksession.getProcessInstance(processInstanceId); VariableScope variableScope = (VariableScope) pi.getContextContainer().getDefaultContext(VariableScope.VARIABLE_SCOPE); for (String name: variableNames) { if (caseFile.getData(name) != null && variableScope.isReadOnly(VariableScope.CASE_FILE_PREFIX+name)) { throw new VariableViolationException(pi.getId(), name,"Variable '" + name + "' is already set and is marked as read only"); } } FactHandle factHandle = ksession.getFactHandle(caseFile); Map<String, Object> remove = new HashMap<>(); variableNames.forEach(p -> remove.put(p, caseFile.getData(p))); CaseEventSupport caseEventSupport = getCaseEventSupport(context); caseEventSupport.fireBeforeCaseDataRemoved(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), remove); variableNames.forEach(p -> caseFile.remove(p)); ksession.update(factHandle, caseFile); triggerRules(ksession); caseEventSupport.fireAfterCaseDataRemoved(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), remove); return null; }