Skip to content

camunda-consulting/camunda-demo-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Camunda Data API

The goal of this project is to provide an easy, consistent framework for creating CRUD rest api’s for interacting with custom business data objects.

Quick Start

See the camunda-demo-starter project to quickly start a fully functional Camunda 7 or 8 demo environment that includes this project.

Once the default demo is started, browse here to see the data api’s available:

Development

This project is a Spring Boot Java Application and uses Spring, JPA, HATEOS, Lombok are used to quickly build CRUD API’s that are standardized and reusable.

Clone this project (the camunda-demo-starter project) to your local machine

git clone https://github.com/camunda-consulting/camunda-demo-starter

The camunda-data-api-demo directory contains all the relevant source code.

Build the project using maven

cd camunda-data-api-demo
mvn clean install

Run the data api.

Note
Remember to stop the data-api container that is started by default as part of the camunda-demo-starter project
cd camunda-data-api-demo
mvn clean spring-boot:run -Dspring-boot.run.profiles=data,user,case,cors

Adding new business data

Two entities exist and work with the prebuilt demo (User and Case). They are preloaded with data. See the User and Case examples in the src/main/java/com/camunda/poc/starter/data.

See the User data api here: http://localhost:9000/api/users

See the Case data api here: http://localhost:9000/api/cases

Note
The ReactJS Demo is configured to use the exposed Data API relatively easily

In many cases you may need to add some customer data.

In order to add a new entity, it’s necessary to create a config, entity and Repository to expose a new API.

For example, let’s say the customer would like to include an entity called TodoItem.

Adding Entity Class

Entities are simple java objects that represent the new business data. For example, create a new class named TodoItem inside a new package named com.camunda.poc.starter.data.todo.entity.

For example:

package com.camunda.poc.starter.data.todo.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import org.springframework.context.annotation.Profile;

import javax.persistence.*;
@Profile("todo")
@Entity(name="poc_todo")
@Getter
@Setter
public class TodoItem {

    private static final long serialVersionUID = -209114353715280555L;

    private @Version
    @JsonIgnore
    Long version;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(nullable=true)
    private String title;

    @Column(nullable=true)
    private String details;

}

Add a Repository Class

By default, entities will be saved to a postgresql database. If you followed the Quick Start steps in the camunda-demo-starter project, the postgres-camunda container should be running.

Add a Spring Data JPA Repository like so:

package com.camunda.poc.starter.data.todo.repo;

import com.camunda.poc.starter.data.todo.entity.TodoItem;
import org.springframework.context.annotation.Profile;
import org.springframework.data.repository.PagingAndSortingRepository;

@Profile("todo")
public interface TodoItemRepository extends PagingAndSortingRepository<TodoItem, Long>{

}

Adding Config Class

The Config class is used to automatically create table objects in the database. Config class also controls the data that is pre-populated inside the postgresql db. When the camunda-data-api project is run, listeners in the config class creates the db schema and refreshes data in the database.

For the TodoItem example, copy the UserEntityCreateConfig.java.

Remember to change this line to match the new Entity:

metadata.addAnnotatedClass(TodoItem.class);

and change the onApplicationEventCreateContact method like so:

    @EventListener
    @org.springframework.core.annotation.Order(20)
    public void onApplicationEventCreateContact(ContextRefreshedEvent event) throws SQLException {


        if (repository.count() == 0) {
            LOGGER.info("\n\n **** Create Todo Item Post Init Hook ***** \n\n ");

            TodoItem todoItem = new TodoItem();
            todoItem.setTitle("Add TodoItem Business Data Object");
            todoItem.setDetails("... this will make the demo awesome!");
            repository.save(todoItem);

            LOGGER.info("\n\n **** TodoItem Created ****** \n\n");
        }
    }

Access new Data Object

Remember to include the new "todo" profile and restart the data-todo api like so:

mvn clean spring-boot:run -Dspring-boot.run.profiles=data,user,case,cors,todo

The new todo item api should be available here:

http://localhost:9000/api/todoItems

Docker Compose

When demoing or distributing it makes sense to build this project with docker-compose. When you follow the "Quick Start" steps in the camunda-demo-starter project, the docker image is already built and deployed as a GitHub Package. But, if you are customizing this project, you can also run the docker-compose command like so:

 docker-compose -f docker-compose.data-api.yml up -d --build data-api

More documentation coming soon …​

TODO: describe how to use pubsub features TODO: describe how to use reactive features TODO: describe how to use redis as a cache TODO: describe how to use kafka