Giter Club home page Giter Club logo

bonita-java-client's Introduction

Bonita Java Client

Bonitasoft

Build Release Maven Central Sonar License

This project is the official web client for Bonita when working with Java (or on the JVM).

It is based on an OpenAPI OpenAPI specification for Bonita 7.15 Enterprise edition. This means that this client includes all Community operations plus some that are only supported by Enterprise editions servers.


  • Cover publicly available http endpoints of Bonita Platform 7.15 and onwards

  • Built-in Bonita authentication support (SSO not supported yet)

  • Higher level code than raw openapi client to ease developer journey

The client library available from Maven Central, you can use it in your Maven project by adding the following to your pom.xml:

<dependency>
    <groupId>org.bonitasoft.web</groupId>
    <artifactId>bonita-java-client</artifactId>
    <version>2.0.0-SNAPSHOT</version>
</dependency>
📎
Snapshots versions are available at https://oss.sonatype.org/content/repositories/snapshots/

The following code creates a java client instance targeting a bonita server listening at http://localhost:8080/bonita. After login in, it queries the deployed processes with pagination parameters (page index: 0,page size: 20)

// Create a client
BonitaClient client = BonitaClient.builder("http://localhost:8080/bonita").build();

// Login
Session session = client.login("username","password");
// Log Bonita server version
log.debug("Bonita version: {}", session.getVersion());

// Use the client 🥳
List businessProcesses = client.processes().searchProcesses(0, 20);

// Logout when done
client.logout();

This client can log HTTP requests made to Bonita Platform.

Different log level are available. Default level is OFF

  • FULL: Headers + Body

  • HEADER: Headers

  • BASIC: HTTP trace (url + verb + response code)

  • OFF: No log

BonitaClient client = BonitaClient.builder("http://localhost:8080/bonita")
        .logContentLevel(LogContentLevel.BASIC)
    .build();

The logger name is org.bonitasoft.web.client.BonitaClient and logging is done with to slf4j so if you’re using logback implementation, you may configure your logger like this :

<logger name="org.bonitasoft.web.client.BonitaClient" level="INFO"/>

The following code show how you can customize the client http timeouts.

BonitaClient client = BonitaClient.builder("http://localhost:8080/bonita")
        .connectTimeoutInSeconds(int connectTimeoutInSeconds)
        .readTimeoutInSeconds(int readTimeoutInSeconds)
        .writeTimeoutInSeconds(int writeTimeoutInSeconds)
    .build();

If you need for any reason to disable ssl certificate check, here is the code to do it:

BonitaClient client = BonitaClient.builder("https://me.bonitacloud.com/")
        // Disable certificate check
        .disableCertificateCheck(true)
    .build();
⚠️
Please note that this is not recommended from a security point of view !
// Create your custom ObjectMapper
ObjectMapper myObjectMapper = new ObjectMapper();

// Configure bonita client to use your custom ObjectMapper
BonitaClient client = BonitaClient.builder("http://localhost:8080/bonita")
        .objectMapper(myObjectMapper)
    .build();
// Create your custom OkHttp client
OkHttpClient myOkHttpClient = new OkHttpClient.Builder().build();

// Configure bonita client to use your custom OkHttp client
BonitaClient client = BonitaClient.builder("http://localhost:8080/bonita")
        okHttpClient(myOkHttpClient)
    .build();

The current implementation of the client use OpenFeign internally. If you need to fine tune the feign aspect, it is possible but remember this may change in future version.

// Create your custom feign builder
Feign.Builder myFeignBuilder = new Feign.Builder();

BonitaClientBuilder builder = BonitaClient.builder("http://localhost:8080/bonita");
// Cast builder to BonitaFeignClientBuilder class
BonitaFeignClientBuilder bonitaClientBuilder = (BonitaFeignClientBuilder) builder;
BonitaClient client = bonitaClientBuilder
        // Configure bonita client to use your custom feign builder
        .feignBuilder(myFeignBuilder)
    .build();

Bonita allow users to define their own custom "named" queries. That’s why this client can’t have java object ready to be mapped to the query results. But the client allow developers to specify the desired returned type when performing custom queries.

As an example, let’s say with have a model in our client project code for Post,Comment and Author defined this way

public interface Post {
    Author getAuthor();
    String getTitle();
    String getContent();
    List<Comment> getComments();
}

public interface Comment {
    Long getUserId();
    LocalDateTime getCreationDate();
	String getContent();
}

public class Author {
    private String firstName;
    private String lastName;
    // Getter and Setter omitted ...
}

Interface with Getter methods are a good choice since we consider the retrieved data as immutable.

Bonus, it allow for lazy fetch of relations as defined in the BDM !

// Count comment and map response to an Integer
Integer count = bonitaClient.bdm().querySingle("com.company.model.Comment", "countForFind", Integer.class);

// List comments and map response to a list of Comment
List<Post> posts = bonitaClient.bdm().query("com.company.model.Post", "find", Post.class);

Post post = posts.get(O);
// This will trigger an HTTP GET request to get the related comments from the BDM
List<Comment> comments = post.getComments();

If you prefer a map style like approach, you can still use the BusinessData class.

List<BusinessData> comments = bonitaClient.bdm().query("com.company.model.Comment", "find", BusinessData.class);
String content = comments.get(0).get("content")
  • a git client

  • a java (jdk8 or higher)

  • maven (optional if you chose to use maven wrapper script)

  • Docker for integration tests

This is a standard maven project. To install the java client library to your local Maven repository, simply execute:

git clone https://github.com/bonitasoft/bonita-java-client.git
cd bonita-java-client/
mvn install

The build should produce under the target/ folder (and in your local maven repository) a jar archive named bonita-java-client-1.0.0-SNAPSHOT.jar

For more details about apache maven, please refer to the documentation

This project uses Spotless to ensure a consistent formatting. To apply the configured formatting rules use the following Maven command:

./mvnw spotless:apply

The OpenAPI spec is retrieve from the [bonita-openapi](https://github.com/bonitasoft/bonita-openapi/) repository releases. To update the spec version you must:

  • Update the bonita-openapi.version property in the pom.xml

  • Run the following Maven command:

./mvnw groovy:execute@update-spec

You can then regenerate the feign stubs.

If the openapi specification changed, you can regenerates the feign stubs with the following command.

⚠️
Be careful, some client stubs are marked as ignored in .openapi-generator-ignore file, since they were customized (like returning a feign.Response instead of a model object)
mvn generate-sources -Dcodegen.skip=false

The adopted worlfow is for now the Gitflow one.

Please refers to this article for more info: https://jeffkreeftmeijer.com/git-flow/

  • Create a branch for the desired version. ex: release/1.0.0. You can use the set-version.sh script to align declared versions in sources (pom.xml,readme.adoc,…​)

  • Push branch, make a pull request to master and review release with others

  • Once you are happy with the content of the release branch, merge pull request to master branch using Merge pull request button (⚠ Do not squash or rebase)

  • Wait the build to succeed

  • Go to https://oss.sonatype.org/ to close and release the staging repository and now you’re done ! 🥳

📎
Do not update your local dev branch after a release has been done ! The release job will perform the dev branch update itself !

The bonitasoft organization on GitHub hosts the project’s source code, issue trackers, and other projects.

Use of this software is granted under the terms of the GNU GENERAL PUBLIC LICENSE.

See the LICENSE for the full license text.

Refer to the CHANGELOG for a complete list of changes in older releases.

bonita-java-client's People

Contributors

akantcheff avatar baptistemesta avatar dependabot[bot] avatar dumitrucorini avatar github-actions[bot] avatar jeromecambon avatar laurentleseigneur avatar rbioteau avatar uguy avatar vhemery avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bonita-java-client's Issues

Problem with setting parenthPath for group (create and update)

Creating and updating groups works for the most part except for the parent path. When i check on the portail the parent path is always empty. I create 2 group, the sfirst is the parent of the second. Bonita refuse to update that field. Here the code i use to update :
GroupUpdateRequest groupUpdateRequest = new GroupUpdateRequest();
groupUpdateRequest.setDescription(group.getDescription());
groupUpdateRequest.setDisplayName(group.getDisplayName());
groupUpdateRequest.setParentPath(group.getParentPath());
groupUpdateRequest.setName(group.getName());

groupAPI.updateGroupById(groupId, groupUpdateRequest);

Problem when searching membership for user

I use this code :
public static List searchForMembership (String userId){
List listFilter = new ArrayList();
listFilter.add("f=user_id="+userId);
List resultSearch = membershipAPI.searchMemberships(0, Integer.MAX_VALUE, listFilter, "ROLE_NAME_ASC", "");
return(resultSearch != null && !resultSearch.isEmpty() ? resultSearch : null);
}
And i have this result in the log :
org.bonitasoft.web.rest.server.framework.exception.APIFilterException: Error on filter : Cant search on filter other than user_id

I put the complete error I get in the log.
MembershipSearchError.txt

Invalid return type for Diagram API

Using the Diagram API:
client.get(DiagramApi.class).getProcessDiagramById("8125541821642636475");

the following exception is raised:
Exception in thread "main" feign.codec.DecodeException: java.util.Map<java.lang.String, java.lang.Object> is not a type supported by this decoder.

Cannot assign human task to user

Hi,

Using HumanTaskApi.updateHumanTaskById(taskId, humanTaskUpdateRequest) has no effect with Bonita Java Client v1.0.0.

Analysing the request body shows that the following JSON is sent by the client:

{
    "assignedId": "123456789"
}

whereas the Bonita User Application sends this JSON:

{
    "assigned_id": "123456789"
}

The HumanTaskUpdateRequest.JSON_PROPERTY_ASSIGNED_ID value should then be equal to "assigned_id" instead of "assignedId" so that the provided user ID is taken into account.

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.