Jadeval

Just A DEcision and VAlidation Library

License

License

Categories

Categories

JADE General Purpose Libraries Utility
GroupId

GroupId

nl.suriani
ArtifactId

ArtifactId

jadeval
Last Version

Last Version

0.4.10
Release Date

Release Date

Type

Type

jar
Description

Description

Jadeval
Just A DEcision and VAlidation Library
Project URL

Project URL

https://github.com/TristanoSuriani/jadeval
Source Code Management

Source Code Management

https://github.com/TristanoSuriani/jadeval

Download jadeval

How to add to project

<!-- https://jarcasting.com/artifacts/nl.suriani/jadeval/ -->
<dependency>
    <groupId>nl.suriani</groupId>
    <artifactId>jadeval</artifactId>
    <version>0.4.10</version>
</dependency>
// https://jarcasting.com/artifacts/nl.suriani/jadeval/
implementation 'nl.suriani:jadeval:0.4.10'
// https://jarcasting.com/artifacts/nl.suriani/jadeval/
implementation ("nl.suriani:jadeval:0.4.10")
'nl.suriani:jadeval:jar:0.4.10'
<dependency org="nl.suriani" name="jadeval" rev="0.4.10">
  <artifact name="jadeval" type="jar" />
</dependency>
@Grapes(
@Grab(group='nl.suriani', module='jadeval', version='0.4.10')
)
libraryDependencies += "nl.suriani" % "jadeval" % "0.4.10"
[nl.suriani/jadeval "0.4.10"]

Dependencies

compile (2)

Group / Artifact Type Version
org.antlr : antlr4 jar 4.8-1
org.apache.maven.plugins : maven-gpg-plugin jar 1.6

test (3)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.6.2
org.mockito : mockito-core jar 3.5.9
org.mockito : mockito-junit-jupiter jar 3.5.9

Project Modules

There are no modules declared in this project.

Jadeval

It was Just A DEcision and VAlidation Library (but now it's much more than that)

Introduction

Jadeval is lightweight open source library that allows to define fact based complex computational models as business decisions, validations and workflows (more is coming), through its own domain specific language for maximum flexibility.

Main concepts

Decisions

Business decisions defines or constraints some aspect of business and resolves with a set of responses. Think about the sentence:

When the customer's age is at least 18 years old and his salary at least 40000 and no previous breaches are found then approve loan

In this example the customer's age, his salary and the presence of previous breaches are the facts that are used to take the decision and 'approve loan' is the response.

Jadeval Decision Language allows to define this decision in almost plain English:

when customerAge >= 18 and hisSalary >= 40000 and foundPreviousBreaches is false then APPROVE_LOAN

Validations

Validations constrant aspects of business and resolves either without a response (sucess) or a validation exception (failure). Think about the sentence:

When the customer's account is blocked stop the process and notify the error

Jadeval Validation Language allows to define this decision in almost plain English:

valid when accountStatus is not blocked

Workflows

A workflow consists of an orchestrated and repeatable pattern of activity. Elements of a workflow include states, transitions between states and the rules the regulate them, as well as task performed as consequence of a state transition. Think about this set of sentences:

Start playing this card game.
Get cards (they will be 37 in total, divided by the two players. The only queen in the deck will be the queen of spades).
Choose a card from opponent's deck.
Offer a card to your opponent.
If you have matching cards (for example two cards with the value 3) you may discard them.
Repeat until both players discarded all their cards and one of them remained with
If you remained with the queen of spades you lost. 

Now reorganise this use case as a set of events. You can find for example:

GameStarted
GotCards
ChosenCardFromOpponentDeck
CardsDiscarded
CardOfferedToOpponent
YouWon
YouLost

You may realise that GameStarted is the entrypoint (root state), YouWon and YouLost are final states and all the other states are intermediate states. Hereby a brief explanation:

  • Root states may flow into intermediate and final states and no state can flow into them
  • Intermediate states may flow to intermediate and final states and can be reached by root and intermediate states
  • Final states can be reached by non-final states and cannot flow to any other state

Now you can defined how these states flow into the others:

from GameStarted to GotCards

from GotCards to ChosenCardFromOpponentDeck

from ChosenCardFromOpponentDeck to YouLost if you have only the queen of spades and your opponent finished the cards
from ChosenCardFromOpponentDeck to CardsDiscarded if there are matching cards
from ChosenCardFromOpponentDeck to CardOfferedToOpponent if there aren't matching cards

from CardsDiscarded to CardOfferedToOpponent if there are more than one card in your deck
from CardsDiscarded to YouWon if you finished your cards and your opponent has only the queen of spades
from CardsDiscarded to ChosenCardFromOpponentDeck if the sum of the cards in both players' decks is greather then 1

Jadeval Workflow Definition language allows to define workflows in a formal but easy to read fashion. Defining this example would like something like this:

root states
    GameStarted

intermediateStates
    GotCards
    ChosenCardFromOpponentDeck
    CardsDiscarded
    CardOfferedToOpponent

final states
    YouWon
    YouLost

transitions
    GameStarted -> GotCards
    GotCards -> ChosenCardFromOpponentDeck

    ChosenCardFromOpponentDeck -> YouLost when numberOfCardsInOpponentDeck is 0 and numberOfCardsInYourDeck is 1 and lastCard is queenOfSpades
    ChosenCardFromOpponentDeck -> CardsDiscarded when thereAreMatchingCards is true
    ChosenCardFromOpponentDeck -> CardOfferedToOpponent when thereAreMatchingCards is false
    
    CardsDiscarded -> CardOfferedToOpponent when numberOfCardsInYourDeck > 1
    CardsDiscarded -> YouWon when numberOfCardsInYourDeck is 0 and opponentHasQueenOfSpades is true
    CardsDiscarded -> ChosenCardFromOpponentDeck when sumOfCardsInBothDecks > 1

State machines

A state machine is similar to a workflow, with a couple of differences:

  • there are no distinction between root, intermediate and final states
  • the state machine does not need to end in a specific state. It doesn't need to end at all.
  • there is no 'play until pause' mechanism. It is possible to move only one step at a time, regardless of the transition being conditional or direct.

Jadeval State machine Definition Language allows to formally define state machines. Hereby an example of a state machine:

state machine
    constants
        $daysToNewSprint = 3

    states
        sprintPlanningPrepared, storyPointsAssigned, sprintGoalDefined, oldSprintClosed, newSprintStarted, sprintInProgress

    transitions
        sprintPlanningPrepared -> storyPointsAssigned when activity is assignStoryPoints
        storyPointsAssigned -> sprintGoalDefined when activity is defineSprintGoal
        sprintGoalDefined -> oldSprintClosed when activity is closeOldSprint
        oldSprintClosed -> newSprintStarted when activity is startNewSprint and sprintApprovedByPO is true
        newSprintStarted -> sprintInProgress
        sprintInProgress -> sprintPlanningPrepared when activity is prepareSprintPlanning and daysToNewSprint == $daysToNewSprint

Import Jadeval in your project with Maven

To import Jadeval simply add this Maven dependency:

<dependency>
    <groupId>nl.suriani</groupId>
    <artifactId>jadeval</artifactId>
    <version>xxx</version>
</dependency>

State of the library

Jadeval is currently in alpha version. This means that it can change considerably between versions, the stability and absence of major bugs in not guaranteed, and it should therefore not be used for production code.

Roadmap

The following features are planned for the next releases of Jadeval:

  • Automatic scan of resource definition files
  • Jadeval XML DSL
  • Support to compare between facts
  • Support for Empty Value in facts
  • Facts expressions
  • Translation of semantic models to diagrams in DOT language for integration with Graphviz.
  • Several improvements to stability and APIs
  • Jadeval Extensions API?

Versions

Version
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.11
0.3.10
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2