Giter Site home page Giter Site logo

egatlovs / variable-management Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 210 KB

An extension to the Camunda API to use bean validation and custom annotations in your execution entities

License: MIT License

Java 100.00%
camunda camunda-bpm camunda-engine bean-validation api execution framework camunda-framework overlay extension

variable-management's Introduction

VariableManagement

Badges

Maven Central Javadoc

Build Status codecov.io License: MIT

Foreword

Variable Management is an extension of the Camunda Java-API. Camunda itself provides a process engine to automate and orchestrate business processes. I personally recognized that executing tasks developing and modeling a process is quite easy. But writing variables and retrieving them from the so called execution can get quite messy. Thats why I code variable-management.

Content

Introduction

This Project provides Objects called Managers which wrap Camunda Services and give you the ability to write and read variables in a different way. See the Topics below to read more about Managers and their abilities.

Managers

Each Manager provides the ability to read, write and remove variables globally and locally. Also every Manager allows access to the wrapped Camunda object.

Following Managers are provided:

  • RuntimeManager
    • This Manager wraps a RuntimeService.
  • TaskManager
    • This Manager wraps a TaskService.
  • ExecutionManager
    • This Manager wraps the current DelegateExecution.

You can use each Manager to write, read or remove an Object from an Execution. The Manager will at first run a Validation using the BeanValidation Spec. That means that you can annotate each field of your Object with the well-known BeanValidation Annotations. After the Validation is successful the Manager will process your Object and it takes care of the Annotations you've used so that you can manipulate the Result. More on Manipulations of an Execution Entity is provided on the Annotations section.

Annotations

Each Annotation gives you the ability to manipulate the Object retrieved or written to the Execution.

Following Annotations are provided:

  • ObjectValue
    • provides following fields:
      • storeFields -> where you can decide if the whole Object is used and serialized with the values below or the Declared Fields them self are used
      • serializationDataFormat -> which takes the Camunda provided serializationDataFormats
      • customSerializationDataFormat -> where you can specify you're own custom Formats
  • FileValue
    • provides following fields:
      • name -> the filename
      • encoding -> the files encoding
      • mimeType -> the files mimeType
  • Ignore
    • tells the Manager to ignore the field
  • FieldName
    • name -> the name to be used (at default the variable name would be used)
    • prefix -> the prefix to be used (if set this would result in a name like: prefix_name)

Getting Started

  1. Create a project using Camundas Maven Archetype for a Process Application (EJB, WAR).
  2. Add the newest dependency of this project.
  3. Create a process and a Service Task with a JavaDelegate.
  4. Create an Object and declare with the provided Annotations.
  5. Inject the ExecutionManager into your Delegate.
  6. Start writing, reading and removing variables.

Example Projects

You got an OpenSource Project using this Framework? -> Send an Email and I will paste the Link for the community!

Documentation

For more Information on this Framework please visit the Documentation.

Purpose

Everyone of us knows the TwitterProcess example of Camunda. Inside the whole process you work with a maximum of maybe ten variables. Most of them are some sort of Human-Written Text where you don't necessary need to apply Constraints or some sort of validation.

Heres a little example of that:

public class MyDelegate implements JavaDelegate {

    @Inject
    TwitterService twitterService;

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        String message = (String) execution.getVariable("message");
        twitterService.tweet(message);
    }

}

This looks pretty easy right? -> Yes but actually... thats an example. Did you notice the String cast? Thats actually the first bit of code where everything starts to look a little bit wrong.

Lets think about a more complex example where you need some form of list and actually you want to throw an exception when size is less than 5.

Pretty easy:

    public void execute(DelegateExecution execution) throws Exception {
        List<String> informations = someService.getInformation();
        if (informations.size() < 5) {
            throw new Exception("failed");
        }
    }

Okay now we have that. Lets think about some sort of service where you get this array from. Of course you can never trust anyone.. thats why you probably want to null-check the array.

So you're code looks like that:

    public void execute(DelegateExecution execution) throws Exception {
        List<String> informations = someService.getInformation();
        if (informations == null || informations.size() < 5) {
            throw new Exception("failed");
        }
        execution.setVariable("informations", informations);
    }

Note that I added a line to save the array inside the execution. Thats also my next concern. You always access and write variables based of a String representing the variable. Think about a process where you want to access a single variable in various different tasks. Thats the point where most developers think about some sort of Enumeration where you store the names of variables and retrieve them elsewhere to access the variable. Thats to ensure, that if someone renames them, everything else will still be functional.

Having all of this accomplished you can model and implement a whole lot of processes. At some point you realize your variables aren't that great when you watch them inside the Camunda cockpit. So you probably want some form of Meta-Data. Lets stick with a prefix to a variable name. Codewise that means you add a field to your Enumeration. After u realize the same prefix is used multiple times you go with multiple Enumerations based on there prefix and each Field actually corresponds to the defined prefix. Just because if you change it, functionality is still provided and code duplication is reduced.

And now think how your code would look like if you gather twenty different variables from some sort of Service and you want each of them inside the execution, all validated differently and you do that for ten Services in ten different tasks.

Yes thats a mess.

If you read through until now and you actually don't think i made a huge mistake, you can see some examples on how I personally tried to make things less messy and try to make everything feel a little more known. Otherwise if you think I'm totally wrong don't hesitate contact me and let me learn from my mistakes.

Code Snippets

Instead of:

    public void execute(DelegateExecution execution) throws Exception {
        String name1 = (String) execution.getVariable("name1");
        String name2 = (String) execution.getVariable("name2");
        String name3 = (String) execution.getVariable("name3");
        String name4 = (String) execution.getVariable("name4");
        String name5 = (String) execution.getVariable("name5");
        String name6 = (String) execution.getVariable("name6");
        String name7 = (String) execution.getVariable("name7");
        String name8 = (String) execution.getVariable("name8");
        String name9 = (String) execution.getVariable("name9");
     
        someObject.setName1(name1);
        // Map Everything to some Object...
        
        // do some logic
    }

You can just write this:

    @Inject
    private ExecutionManager manager;
    
    public void execute(DelegateExecution execution) throws Exception {
       SomeObject someObject = manager.getVariable(SomeObject.class);
       //do some logic
    }

Roadmap

Here are some plans for the next weeks:

  • Work on Project "Logging with Correlation ids"
  • Work on Managed Fields to Inject the Fields you desire directly in your JavaDelegate

Epilogue

Problems using this framework?

  • Create an issue i will try to solve problems as soon as possible.

Thanks for reading everything!

Please make sure to contact me for any question and don't hesitate to contribute.

variable-management's People

Contributors

egatlovs avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

variable-management's Issues

taskmanager

  • must use bean validation on each execution change

Add each typed value camunda supports

Supported types:

boolean: Instances of java.lang.Boolean
bytes: Instances of byte[]
short: Instances of java.lang.Short
integer: Instances of java.lang.Integer
long: Instances of java.lang.Long
double: Instances of java.lang.Double
date: Instances of java.util.Date
string: Instances of java.lang.String
null: null references

File
Custom object

ArrayField

Create managed array field for task execution and runtime

MapField

Create map field for managed execution task and runtime

annotation execution

  • must provide following fields:

storeFields = boolean
storeStartegy = StoreStrategy

  • must have default values

Create readme

should contain:

  • Something about why i wrote it
  • description on how to use it
  • examples on how to use it
  • ask for feedback

Edit readme and add future plans

As of project TypedValue support
the current api will break and a new release will happen in a few weeks.

The readme should contain those information and describe future plans with this project.

StringField

Create managed string field for task execution and runtime

annotation executionfield

  • must provide following fields:
    name = String
    prefix = String
    config = Config

  • prefix default is null

  • config default is null

  • name default is null

annotation processing logic

  • logic processing annotations on objects written should be determined
  • interfaces and different classes should be provided to use same logic in each manager

interface manager

  • must provide methods to retieve objects
  • must declare core functionality for each extension

Class that retrieves annotation data

Class should provide annotations necessary to process variable writes and reads
If necessary the class should contain other classes to make it more readable

Start release 2

Everything inside this project is more or less breaking the api of release 1.

So this project should finish up with
a new release of Version 2.0.0

SetField

Create managed set field for task execution and runtime

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.