This project is designed to simplify communication between a java backend and the Camunda 8 operate. This project is still a draft.
Simply build a CamundaOperateClient that takes an authentication and the operate url as parameters.
SimpleAuthentication sa = new SimpleAuthentication("demo", "demo", "http://localhost:8081");
CamundaOperateClient client = new CamundaOperateClient.Builder().operateUrl("http://localhost:8081").authentication(sa).build();
//search process definitions based on filters
ProcessDefinitionFilter processDefinitionFilter = new ProcessDefinitionFilter.Builder().name("Customer Onboarding").build();
SearchQuery procDefQuery = new SearchQuery.Builder().withFilter(processDefinitionFilter).withSize(20).withSort(new Sort("version", SortOrder.ASC)).build();
List<ProcessDefinition> processDefinitions = client.searchProcessDefinitions(procDefQuery);
//get a process definition by its key
ProcessDefinition def = client.getProcessDefinition(1L);
//search process instances based on filters
ProcessInstanceFilter instanceFilter = new ProcessInstanceFilter.Builder().bpmnProcessId("customer_onboarding_en").startDate(new DateFilter(new Date(), DateFilterRange.MONTH)).build();
SearchQuery instanceQuery = new SearchQuery.Builder().withFilter(instanceFilter).withSize(20).withSort(new Sort("state", SortOrder.ASC)).build();
List<ProcessInstance> instances = client.searchProcessInstances(instanceQuery);
//get a process instance by its key
ProcessInstance instance = client.getProcessInstance(instances.get(0).getKey());
//search flownode instances based on filters
FlownodeInstanceFilter flownodeFilter = new FlownodeInstanceFilter.Builder()
.processInstanceKey(4L).startDate(new DateFilter(new Date(), DateFilterRange.YEAR)).build();
SearchQuery flownodeQuery = new SearchQuery.Builder().withFilter(flownodeFilter).withSize(20).withSort(new Sort("state", SortOrder.ASC)).build();
List<FlownodeInstance> flownodes = client.searchFlownodeInstances(flownodeQuery);
//get a flownode instance by its key
FlownodeInstance flownodes = client.getFlownodeInstance(flownodes.get(0).getKey());
//search variables based on filters
VariableFilter variableFilter = new VariableFilter.Builder().processInstanceKey(4L).build();
SearchQuery varQuery = new SearchQuery.Builder().withFilter(variableFilter).withSize(5).withSort(new Sort("name", SortOrder.ASC)).build();
List<Variable> variables = client.searchVariables(varQuery);
//get a variable by its key
Variable var = client.getVariable(variables.get(0).getKey());
//search incidents based on filters
IncidentFilter incidentFilter = new IncidentFilter.Builder().creationTime(new DateFilter(new Date(), DateFilterRange.YEAR)).build();
SearchQuery incidentQuery = new SearchQuery.Builder().withFilter(incidentFilter).withSize(20).withSort(new Sort("state", SortOrder.ASC)).build();
List<Incident> incidents = client.searchIncidents(incidentQuery);
//get a incident by its key
Incident incident = client.getIncident(incidents.get(0).getKey());
You can use the SimpleAuthentication to connect to a local Camunda TaskList if your setup is "simple": without identity and keycloak.
To connect to the SaaS Operate, you need to use the SaasAuthentication rather than the SimpleAuthentication. The SaaSAuthentication requires the ClientId and SecretId
SaasAuthentication sa = new SaasAuthentication("2~nB1MwkUU45FuXXX", "aBRKtreXQF3uD2MYYY");
CamundaOperateClient client = new CamundaOperateClient.Builder().authentication(sa)
.taskListUrl("https://bru-2.tasklist.camunda.io/757dbc30-5127-4bed-XXXX-XXXXXXXXXXXX").build();
To connect to the Local TaskList with Identity & Keycloak, you need to use the LocalIdentityAuthentication. The SaaSAuthentication requires the clientId and clientSecret. You can also change the Keycloak realm and the baseUrl depending on your installation.
LocalIdentityAuthentication la = new LocalIdentityAuthentication().clientId("java").clientSecret("foTPogjlI0hidwbDZcYFWzmU8FOQwLx0").baseUrl("http://localhost:18080").keycloakRealm("camunda-platform");
CamundaOperateClient client = new CamundaOperateClient.Builder().authentication(la)
.operateUrl("http://localhost:8081/").build();
If you're using an older version of Camunda SaaS or you're having a local setup without Keycloak, you could also query the same APIs as Operate UI. In such a case, you might want to use the Beta client :
SimpleAuthentication sa = new SimpleAuthentication("demo", "demo", "http://localhost:8081");
CamundaOperateClient client = new CamundaOperateClient.Builder().beta().operateUrl("http://localhost:8081").authentication(sa).build();
JsonNode json = ((CamundaOperateBetaClient) client).getFlowNodeStates(2L);
AuditTrail auditTrail = ((CamundaOperateBetaClient) client).getAuditTrail(2L);
Obviously, as soon as the exposed APIs will be sufficient, we should get rid of this Beta client.
You can import it to your maven or gradle project as a dependency
<dependency>
<groupId>io.camunda</groupId>
<artifactId>camunda-operate-client-java</artifactId>
<version>1.2.0</version>
</dependency>
A similar library is available for tasklist there: camunda-tasklist-client-java