Skip to content

Commit

Permalink
chore(optimize): exclude standalone tasks from optimize queries (#4879)
Browse files Browse the repository at this point in the history
related to OPT#4735
  • Loading branch information
PHWaechtler authored Jan 9, 2025
1 parent 50989d8 commit 7c08513
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@
<if test="parameter.finishedAfter == null and parameter.finishedAt == null">
and RES.END_TIME_ is not null
</if>
and TASK_DEF_KEY_ is not null
</where>

ORDER BY RES.END_TIME_ ASC
Expand All @@ -758,6 +759,7 @@
and RES.START_TIME_ = #{parameter.startedAt}
</if>
and RES.END_TIME_ is null
and TASK_DEF_KEY_ is not null
</where>

ORDER BY RES.START_TIME_ ASC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Set;

import org.camunda.bpm.engine.AuthorizationService;
import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.IdentityService;
import org.camunda.bpm.engine.ProcessEngineConfiguration;
import org.camunda.bpm.engine.RuntimeService;
Expand Down Expand Up @@ -69,6 +70,7 @@ public class GetCompletedHistoricTaskInstancesForOptimizeTest {
private RuntimeService runtimeService;
private AuthorizationService authorizationService;
private TaskService taskService;
private HistoryService historyService;


@Before
Expand All @@ -80,6 +82,7 @@ public void init() {
runtimeService = engineRule.getRuntimeService();
authorizationService = engineRule.getAuthorizationService();
taskService = engineRule.getTaskService();
historyService = engineRule.getHistoryService();

createUser(userId);
}
Expand All @@ -95,6 +98,9 @@ public void cleanUp() {
for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
authorizationService.deleteAuthorization(authorization.getId());
}
for (HistoricTaskInstance task: historyService.createHistoricTaskInstanceQuery().list()) {
historyService.deleteHistoricTaskInstance(task.getId());
}
ClockUtil.reset();
}

Expand Down Expand Up @@ -291,6 +297,20 @@ public void fetchOnlyCompletedTasks() {
assertThat(completedHistoricTaskInstances.get(0).getTaskDefinitionKey(), is("userTask1"));
}

@Test
public void doNotReturnCompletedStandaloneTasks() {
// given
Task task = taskService.newTask("standaloneTaskId");
taskService.saveTask(task);
completeAllUserTasks();

// when
List<HistoricTaskInstance> completedHistoricTaskInstances =
optimizeService.getCompletedHistoricTaskInstances(null, null, 10);

// then
assertTrue(completedHistoricTaskInstances.isEmpty());
}

private Date pastDate() {
return new Date(2L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;

import java.util.Date;
import java.util.List;

import org.camunda.bpm.engine.AuthorizationService;
import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.IdentityService;
import org.camunda.bpm.engine.ProcessEngineConfiguration;
import org.camunda.bpm.engine.RuntimeService;
Expand Down Expand Up @@ -67,7 +68,7 @@ public class GetRunningHistoricTaskInstancesForOptimizeTest {
private RuntimeService runtimeService;
private AuthorizationService authorizationService;
private TaskService taskService;

private HistoryService historyService;

@Before
public void init() {
Expand All @@ -78,6 +79,7 @@ public void init() {
runtimeService = engineRule.getRuntimeService();
authorizationService = engineRule.getAuthorizationService();
taskService = engineRule.getTaskService();
historyService = engineRule.getHistoryService();

createUser(userId);
}
Expand All @@ -93,6 +95,9 @@ public void cleanUp() {
for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
authorizationService.deleteAuthorization(authorization.getId());
}
for (HistoricTaskInstance task : historyService.createHistoricTaskInstanceQuery().list()) {
historyService.deleteHistoricTaskInstance(task.getId());
}
ClockUtil.reset();
}

Expand Down Expand Up @@ -162,7 +167,7 @@ public void startedAtParameterWorks() {
engineRule.getRuntimeService().startProcessInstanceByKey("process");

// when
List<HistoricTaskInstance> runningHistoricTaskInstances =
List<HistoricTaskInstance> runningHistoricTaskInstances =
optimizeService.getRunningHistoricTaskInstances(null, now, 10);

// then
Expand Down Expand Up @@ -272,6 +277,26 @@ public void fetchOnlyRunningTasks() {
assertThat(runningHistoricTaskInstances.get(0).getTaskDefinitionKey(), is("userTask2"));
}

@Test
public void doNotReturnRunningStandaloneTasks() {
try {
// given
Task task = taskService.newTask("standaloneTaskId");
taskService.saveTask(task);

// when
List<HistoricTaskInstance> runningHistoricTaskInstances = optimizeService.getRunningHistoricTaskInstances(null,
null, 10);

// then
assertTrue(runningHistoricTaskInstances.isEmpty());
} finally {
for (Task task : taskService.createTaskQuery().list()) {
taskService.deleteTask(task.getId());
}
}
}

private Date pastDate() {
return new Date(2L);
}
Expand Down

0 comments on commit 7c08513

Please sign in to comment.