Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare v2 client #193

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.camunda.tasklist.bootstrapping;

import io.camunda.tasklist.CamundaTaskListClient;
import io.camunda.tasklist.CamundaTaskListClientV1;
import io.camunda.tasklist.CamundaTasklistClientConfiguration;
import io.camunda.tasklist.CamundaTasklistClientConfiguration.DefaultProperties;
import io.camunda.tasklist.auth.SimpleAuthentication;
Expand All @@ -10,9 +10,9 @@
import java.time.Duration;

public class Bootstrapper {
public CamundaTaskListClient create() {
public CamundaTaskListClientV1 create() {
try {
return new CamundaTaskListClient(
return new CamundaTaskListClientV1(
new CamundaTasklistClientConfiguration(
new SimpleAuthentication(
new SimpleCredential(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import static org.junit.jupiter.api.Assertions.*;

import io.camunda.tasklist.CamundaTaskListClient;
import io.camunda.tasklist.CamundaTaskListClientV1;
import org.junit.jupiter.api.Test;

public class BootstrappingTest {
@Test
void shouldRun() {
CamundaTaskListClient camundaTaskListClient = new Bootstrapper().create();
CamundaTaskListClientV1 camundaTaskListClient = new Bootstrapper().create();
assertNotNull(camundaTaskListClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import io.camunda.tasklist.CamundaTaskListClient;
import io.camunda.tasklist.CamundaTaskListClientV1;
import io.camunda.tasklist.CamundaTasklistClientConfiguration;
import io.camunda.tasklist.CamundaTasklistClientConfiguration.DefaultProperties;
import io.camunda.tasklist.auth.JwtAuthentication;
Expand Down Expand Up @@ -46,7 +47,7 @@ public CamundaTaskListClient createTasklistClient() throws MalformedURLException
tasklistUrl,
zeebeClient,
new DefaultProperties(returnVariables, loadTruncatedVariables, useZeebeUserTasks));
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
CamundaTaskListClient client = new CamundaTaskListClientV1(configuration);
return client;
}
}
Expand Down Expand Up @@ -81,7 +82,7 @@ public CamundaTaskListClient createTasklistClient() throws MalformedURLException
tasklistUrl,
zeebeClient,
new DefaultProperties(returnVariables, loadTruncatedVariables, useZeebeUserTasks));
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
CamundaTaskListClient client = new CamundaTaskListClientV1(configuration);
return client;
}
}
Expand Down Expand Up @@ -114,7 +115,7 @@ public CamundaTaskListClient createTasklistClient() throws MalformedURLException
tasklistUrl,
zeebeClient,
new DefaultProperties(returnVariables, loadTruncatedVariables, useZeebeUserTasks));
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
CamundaTaskListClient client = new CamundaTaskListClientV1(configuration);
return client;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.camunda.client;

/** This is a placeholder class until the actual camunda client can be used */
@Deprecated
public interface CamundaClient {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package io.camunda.tasklist;

import io.camunda.tasklist.CamundaTasklistClientConfiguration.DefaultProperties;
import io.camunda.tasklist.dto.Pagination;
import io.camunda.tasklist.dto.SearchType;
import io.camunda.tasklist.dto.Task;
import io.camunda.tasklist.dto.TaskList;
import io.camunda.tasklist.dto.TaskSearch;
import io.camunda.tasklist.dto.Variable;
import io.camunda.tasklist.exception.TaskListException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public abstract class AbstractCamundaTaskListClient implements CamundaTaskListClient {
private final DefaultProperties defaultProperties;

public AbstractCamundaTaskListClient(DefaultProperties defaultProperties) {
this.defaultProperties = defaultProperties;
}

@Override
public Task getTask(String taskId) throws TaskListException {
return getTask(taskId, defaultProperties.returnVariables());
}

@Override
public List<Variable> getVariables(String taskId) throws TaskListException {
return getVariables(taskId, defaultProperties.loadTruncatedVariables());
}

@Override
public TaskList before(TaskList taskList) throws TaskListException {
return paginate(taskList, SearchType.BEFORE);
}

@Override
public TaskList beforeOrEquals(TaskList taskList) throws TaskListException {
return paginate(taskList, SearchType.BEFORE_OR_EQUAL);
}

@Override
public TaskList after(TaskList taskList) throws TaskListException {
return paginate(taskList, SearchType.AFTER);
}

@Override
public TaskList afterOrEqual(TaskList taskList) throws TaskListException {
return paginate(taskList, SearchType.AFTER_OR_EQUAL);
}

@Override
public void loadVariables(List<Task> tasks) throws TaskListException {
loadVariables(tasks, defaultProperties.loadTruncatedVariables());
}

@Override
public void loadVariables(List<Task> tasks, boolean loadTruncated) throws TaskListException {
try {
Map<String, Future<List<Variable>>> futures = new HashMap<>();
Map<String, Task> taskMap = new HashMap<>();
for (Task task : tasks) {
taskMap.put(task.getId(), task);
futures.put(
task.getId(),
CompletableFuture.supplyAsync(
() -> {
try {
return getVariables(task.getId(), loadTruncated);
} catch (TaskListException e) {
return null;
}
}));
}
for (Map.Entry<String, Future<List<Variable>>> varFutures : futures.entrySet()) {
taskMap.get(varFutures.getKey()).setVariables(varFutures.getValue().get());
}
futures.clear();
taskMap.clear();
} catch (ExecutionException | InterruptedException e) {
throw new TaskListException("Error loading task variables", e);
}
}

@Override
public TaskList getTasks(TaskSearch search) throws TaskListException {
if (search.getWithVariables() == null) {
search.setWithVariables(defaultProperties.returnVariables());
}
return getTasksInternal(search);
}

protected abstract TaskList getTasksInternal(TaskSearch search) throws TaskListException;

private TaskList paginate(TaskList taskList, SearchType direction) throws TaskListException {
if (taskList.getSearch().getPagination() == null
|| taskList.getSearch().getPagination().getPageSize() == null) {
throw new TaskListException(
"Before/After/AfterOrEquals search are only possible if a pageSize is set");
}
if (taskList.getItems() == null || taskList.getItems().isEmpty()) {
throw new TaskListException(
"Before/After/AfterOrEquals search are only possible if some items are present");
}

TaskSearch newSearch =
taskList.getSearch().clone().setPagination(getSearchPagination(taskList, direction));
return getTasks(newSearch);
}

private Pagination getSearchPagination(TaskList taskList, SearchType type) {
return switch (type) {
case BEFORE ->
new Pagination.Builder()
.pageSize(taskList.getSearch().getPagination().getPageSize())
.before(taskList.first().getSortValues())
.build();
case BEFORE_OR_EQUAL ->
new Pagination.Builder()
.pageSize(taskList.getSearch().getPagination().getPageSize())
.beforeOrEqual(taskList.first().getSortValues())
.build();
case AFTER ->
new Pagination.Builder()
.pageSize(taskList.getSearch().getPagination().getPageSize())
.after(taskList.last().getSortValues())
.build();
default ->
new Pagination.Builder()
.pageSize(taskList.getSearch().getPagination().getPageSize())
.afterOrEqual(taskList.last().getSortValues())
.build();
};
}
}
Loading
Loading