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 for v2 client #138

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ ObjectMapper objectMapper = new ObjectMapper();
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
CamundaOperateClient client = new CamundaOperateClientV1(configuration);
```

Build a Camunda Operate client with identity authentication:
Expand All @@ -140,14 +140,15 @@ URL authUrl =
"http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token")
.toURL();
// bootstrapping
JwtCredential credentials = new JwtCredential(clientId, clientSecret, audience, authUrl, scope);
JwtCredential credentials =
new JwtCredential(clientId, clientSecret, audience, authUrl, scope);
ObjectMapper objectMapper = new ObjectMapper();
TokenResponseMapper tokenResponseMapper = new JacksonTokenResponseMapper(objectMapper);
JwtAuthentication authentication = new JwtAuthentication(credentials, tokenResponseMapper);
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
CamundaOperateClient client = new CamundaOperateClientV1(configuration);
```

Build a Camunda Operate client for Saas:
Expand All @@ -169,7 +170,7 @@ JwtAuthentication authentication = new JwtAuthentication(credentials, tokenRespo
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
CamundaOperateClient client = new CamundaOperateClientV1(configuration);
```

## Getting and Searching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.camunda.operate.CamundaOperateClient;
import io.camunda.operate.CamundaOperateClientConfiguration;
import io.camunda.operate.CamundaOperateClientV1;
import io.camunda.operate.auth.JwtAuthentication;
import io.camunda.operate.auth.JwtCredential;
import io.camunda.operate.auth.SimpleAuthentication;
Expand Down Expand Up @@ -32,7 +33,7 @@ public CamundaOperateClient createOperateClient() throws MalformedURLException {
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
CamundaOperateClient client = new CamundaOperateClientV1(configuration);
return client;
}
}
Expand All @@ -58,7 +59,7 @@ public CamundaOperateClient createOperateClient() throws MalformedURLException {
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
CamundaOperateClient client = new CamundaOperateClientV1(configuration);
return client;
}
}
Expand All @@ -81,7 +82,7 @@ public CamundaOperateClient createOperateClient() throws MalformedURLException {
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
CamundaOperateClient client = new CamundaOperateClientV1(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
@@ -1,102 +1,28 @@
package io.camunda.operate;

import static io.camunda.operate.model.TypeReferences.*;

import com.fasterxml.jackson.core.type.TypeReference;
import io.camunda.operate.exception.OperateException;
import io.camunda.operate.http.DefaultHttpClient;
import io.camunda.operate.http.HttpClient;
import io.camunda.operate.model.*;
import io.camunda.operate.search.DecisionDefinitionFilter;
import io.camunda.operate.search.DecisionInstanceFilter;
import io.camunda.operate.search.DecisionRequirementsFilter;
import io.camunda.operate.search.Filter;
import io.camunda.operate.search.FlowNodeInstanceFilter;
import io.camunda.operate.search.IncidentFilter;
import io.camunda.operate.search.ProcessDefinitionFilter;
import io.camunda.operate.search.ProcessInstanceFilter;
import io.camunda.operate.model.ChangeStatus;
import io.camunda.operate.model.DecisionDefinition;
import io.camunda.operate.model.DecisionInstance;
import io.camunda.operate.model.DecisionRequirements;
import io.camunda.operate.model.FlowNodeInstance;
import io.camunda.operate.model.FlowNodeStatistics;
import io.camunda.operate.model.Incident;
import io.camunda.operate.model.ProcessDefinition;
import io.camunda.operate.model.ProcessInstance;
import io.camunda.operate.model.SearchResult;
import io.camunda.operate.model.Variable;
import io.camunda.operate.search.SearchQuery;
import io.camunda.operate.search.VariableFilter;
import io.camunda.zeebe.model.bpmn.Bpmn;
import io.camunda.zeebe.model.bpmn.BpmnModelInstance;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CamundaOperateClient {

private final HttpClient httpClient;

private CamundaOperateClient(HttpClient httpClient) {
this.httpClient = httpClient;
}

public CamundaOperateClient(CamundaOperateClientConfiguration configuration) {
this(buildOperateHttpClient(configuration));
}

private static HttpClient buildOperateHttpClient(
CamundaOperateClientConfiguration configuration) {
// load the config map
Map<TypeReference<?>, String> map = new HashMap<>();
// process definitions
map.put(searchProcessDefinition, "/process-definitions/search");
map.put(processDefinition, "/process-definitions/{key}");
map.put(processDefinitionXml, "/process-definitions/{key}/xml");
// decision definition
map.put(searchDecisionDefinition, "/decision-definitions/search");
map.put(decisionDefinition, "/decision-definitions/{key}");
// decision instance
map.put(searchDecisionInstance, "/decision-instances/search");
map.put(decisionInstance, "/decision-instances/{id}");
// flownode instance
map.put(searchFlowNodeInstance, "/flownode-instances/search");
map.put(flowNodeInstance, "/flownode-instances/{key}");
// variable
map.put(searchVariable, "/variables/search");
map.put(variable, "/variables/{key}");
// process instances
map.put(searchProcessInstance, "/process-instances/search");
map.put(processInstance, "/process-instances/{key}");
map.put(deleteProcessInstance, "/process-instances/{key}");
map.put(flownodeStatistics, "/process-instances/{key}/statistics");
map.put(sequenceFlows, "/process-instances/{key}/sequence-flows");
// decision requirements
map.put(searchDecisionRequirements, "/drd/search");
map.put(decisionRequirements, "/drd/{key}");
map.put(decisionRequirementsXml, "/drd/{key}/xml");
// incident
map.put(searchIncident, "/incidents/search");
map.put(incident, "/incidents/{key}");
public interface CamundaOperateClient {
ProcessDefinition getProcessDefinition(Long key) throws OperateException;

try {
return new DefaultHttpClient(
URI.create(formatUrl(configuration.baseUrl().toString() + "/v1")).toURL(),
configuration.authentication(),
configuration.httpClient(),
configuration.objectMapper(),
map);
} catch (MalformedURLException e) {
throw new RuntimeException("Error while initializing operate http client", e);
}
}

private static String formatUrl(String url) {
if (url.endsWith("/")) {
return url.substring(0, url.length() - 1);
}
return url;
}

public ProcessDefinition getProcessDefinition(Long key) throws OperateException {
return httpClient.get(processDefinition, key(key));
}

public BpmnModelInstance getProcessDefinitionModel(Long key) throws OperateException {
default BpmnModelInstance getProcessDefinitionModel(Long key) throws OperateException {
String xml = getProcessDefinitionXml(key);
try {
InputStream processInputStream = new ByteArrayInputStream(xml.getBytes());
Expand All @@ -106,143 +32,86 @@ public BpmnModelInstance getProcessDefinitionModel(Long key) throws OperateExcep
}
}

public String getProcessDefinitionXml(Long key) throws OperateException {
return httpClient.get(processDefinitionXml, key(key));
}
String getProcessDefinitionXml(Long key) throws OperateException;

public List<ProcessDefinition> searchProcessDefinitions(SearchQuery query)
default List<ProcessDefinition> searchProcessDefinitions(SearchQuery query)
throws OperateException {
return searchProcessDefinitionResults(query).getItems();
}

public SearchResult<ProcessDefinition> searchProcessDefinitionResults(SearchQuery query)
throws OperateException {
assertSearchQueryType(ProcessDefinitionFilter.class, query);
return httpClient.post(searchProcessDefinition, query);
}
SearchResult<ProcessDefinition> searchProcessDefinitionResults(SearchQuery query)
throws OperateException;

public List<DecisionDefinition> searchDecisionDefinitions(SearchQuery query)
default List<DecisionDefinition> searchDecisionDefinitions(SearchQuery query)
throws OperateException {
return searchDecisionDefinitionResults(query).getItems();
}

public SearchResult<DecisionDefinition> searchDecisionDefinitionResults(SearchQuery query)
throws OperateException {
assertSearchQueryType(DecisionDefinitionFilter.class, query);
return httpClient.post(searchDecisionDefinition, query);
}
SearchResult<DecisionDefinition> searchDecisionDefinitionResults(SearchQuery query)
throws OperateException;

public List<DecisionInstance> searchDecisionInstances(SearchQuery query) throws OperateException {
default List<DecisionInstance> searchDecisionInstances(SearchQuery query)
throws OperateException {
return searchDecisionInstanceResults(query).getItems();
}

public SearchResult<DecisionInstance> searchDecisionInstanceResults(SearchQuery query)
throws OperateException {
assertSearchQueryType(DecisionInstanceFilter.class, query);
return httpClient.post(searchDecisionInstance, query);
}
SearchResult<DecisionInstance> searchDecisionInstanceResults(SearchQuery query)
throws OperateException;

public List<FlowNodeInstance> searchFlowNodeInstances(SearchQuery query) throws OperateException {
default List<FlowNodeInstance> searchFlowNodeInstances(SearchQuery query)
throws OperateException {
return searchFlowNodeInstanceResults(query).getItems();
}

public SearchResult<FlowNodeInstance> searchFlowNodeInstanceResults(SearchQuery query)
throws OperateException {
assertSearchQueryType(FlowNodeInstanceFilter.class, query);
return httpClient.post(searchFlowNodeInstance, query);
}
SearchResult<FlowNodeInstance> searchFlowNodeInstanceResults(SearchQuery query)
throws OperateException;

public List<Variable> searchVariables(SearchQuery query) throws OperateException {
default List<Variable> searchVariables(SearchQuery query) throws OperateException {
return searchVariableResults(query).getItems();
}

public SearchResult<Variable> searchVariableResults(SearchQuery query) throws OperateException {
assertSearchQueryType(VariableFilter.class, query);
return httpClient.post(searchVariable, query);
}
SearchResult<Variable> searchVariableResults(SearchQuery query) throws OperateException;

public List<ProcessInstance> searchProcessInstances(SearchQuery query) throws OperateException {
default List<ProcessInstance> searchProcessInstances(SearchQuery query) throws OperateException {
return searchProcessInstanceResults(query).getItems();
}

public SearchResult<ProcessInstance> searchProcessInstanceResults(SearchQuery query)
throws OperateException {
assertSearchQueryType(ProcessInstanceFilter.class, query);
return httpClient.post(searchProcessInstance, query);
}
SearchResult<ProcessInstance> searchProcessInstanceResults(SearchQuery query)
throws OperateException;

public List<DecisionRequirements> searchDecisionRequirements(SearchQuery query)
default List<DecisionRequirements> searchDecisionRequirements(SearchQuery query)
throws OperateException {
return searchDecisionRequirementsResults(query).getItems();
}

public SearchResult<DecisionRequirements> searchDecisionRequirementsResults(SearchQuery query)
throws OperateException {
assertSearchQueryType(DecisionRequirementsFilter.class, query);
return httpClient.post(searchDecisionRequirements, query);
}
SearchResult<DecisionRequirements> searchDecisionRequirementsResults(SearchQuery query)
throws OperateException;

public List<Incident> searchIncidents(SearchQuery query) throws OperateException {
default List<Incident> searchIncidents(SearchQuery query) throws OperateException {
return searchIncidentResults(query).getItems();
}

public SearchResult<Incident> searchIncidentResults(SearchQuery query) throws OperateException {
assertSearchQueryType(IncidentFilter.class, query);
return httpClient.post(searchIncident, query);
}

public ProcessInstance getProcessInstance(Long key) throws OperateException {
return httpClient.get(processInstance, Map.of("key", String.valueOf(key)));
}

public ChangeStatus deleteProcessInstance(Long key) throws OperateException {
return httpClient.delete(deleteProcessInstance, key(key));
}
SearchResult<Incident> searchIncidentResults(SearchQuery query) throws OperateException;

public List<FlowNodeStatistics> getFlowNodeStatistics(Long key) throws OperateException {
return httpClient.get(flownodeStatistics, key(key));
}
ProcessInstance getProcessInstance(Long key) throws OperateException;

public List<String> getSequenceFlows(Long key) throws OperateException {
return httpClient.get(sequenceFlows, key(key));
}
ChangeStatus deleteProcessInstance(Long key) throws OperateException;

public FlowNodeInstance getFlowNodeInstance(Long key) throws OperateException {
return httpClient.get(flowNodeInstance, key(key));
}
List<FlowNodeStatistics> getFlowNodeStatistics(Long key) throws OperateException;

public Incident getIncident(Long key) throws OperateException {
return httpClient.get(incident, key(key));
}
List<String> getSequenceFlows(Long key) throws OperateException;

public DecisionDefinition getDecisionDefinition(Long key) throws OperateException {
return httpClient.get(decisionDefinition, key(key));
}
FlowNodeInstance getFlowNodeInstance(Long key) throws OperateException;

public DecisionRequirements getDecisionRequirements(Long key) throws OperateException {
return httpClient.get(decisionRequirements, key(key));
}
Incident getIncident(Long key) throws OperateException;

public String getDecisionRequirementsXml(Long key) throws OperateException {
return httpClient.get(decisionRequirementsXml, key(key));
}
DecisionDefinition getDecisionDefinition(Long key) throws OperateException;

public DecisionInstance getDecisionInstance(String id) throws OperateException {
return httpClient.get(decisionInstance, Map.of("id", id));
}
DecisionRequirements getDecisionRequirements(Long key) throws OperateException;

public Variable getVariable(Long key) throws OperateException {
return httpClient.get(variable, key(key));
}
String getDecisionRequirementsXml(Long key) throws OperateException;

private Map<String, String> key(Long key) {
return Map.of("key", String.valueOf(key));
}
DecisionInstance getDecisionInstance(String id) throws OperateException;

private void assertSearchQueryType(Class<? extends Filter> type, SearchQuery query) {
if (query.getFilter() != null && !query.getFilter().getClass().isAssignableFrom(type)) {
throw new IllegalStateException(
"Expected filter of type " + type + " but got " + query.getFilter().getClass());
}
}
Variable getVariable(Long key) throws OperateException;
}
Loading
Loading