Coder Social home page Coder Social logo

parth-99 / camunda-operate-client-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from camunda-community-hub/camunda-operate-client-java

0.0 0.0 0.0 117 KB

Java client for the Operate API of Camunda Platform 8

License: Apache License 2.0

Java 100.00%

camunda-operate-client-java's Introduction

Community Extension Compatible with: Camunda Platform 8

Camunda Operate Client

This project is designed to simplify communication between a java backend and the Camunda 8 operate. This project is still a draft.

How to use the client

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());

Authentication

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();

Use the Beta client

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.

use it in your project

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>

Note

A similar library is available for tasklist there: camunda-tasklist-client-java

camunda-operate-client-java's People

Contributors

chdame avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.