All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ee.telekom.workflow.api.GraphBuilder Maven / Gradle / Ivy

Go to download

Telekom-workflow-engine core provides the runtime environment for workflow execution together with all the supporting services (clustering, persistence, error handling etc).

There is a newer version: 1.6.3
Show newest version
package ee.telekom.workflow.api;

import ee.telekom.workflow.graph.Graph;
import ee.telekom.workflow.graph.Node;
import ee.telekom.workflow.graph.core.GraphImpl;

/**
 * Builds a {@link Graph} based on a {@link Tree} of {@link Row}s. 
 */
public class GraphBuilder{

    private NodeBuilder nodeBuilder = new NodeBuilder();
    private TransitionBuilder transitionBuilder = new TransitionBuilder();
    private GraphImpl graph;
    private Tree root;

    public GraphBuilder( String name, int version, Tree root ){
        this.graph = new GraphImpl( name, version );
        this.root = root;
    }

    /**
     * Builds the {@link Graph} based on the tree. The depth's of a node in the tree equals the level of indentation of
     * a row in the typical formating. For instance, the following definition has a number of rows with depth 1 and one row
     * with depth 2.
     * 
     *   .start()
     *   .if_(1,"condition)
     *     .value("account").call(2,"accountService","findAccount","{accountId}");
     *   .endIf()
     *   .end()
     * 
*
    *
  1. Traverses the tree in pre-order and creates a {@link Node} for every row. There are few rows such as START that actually don't produce a node. *
  2. Creates transitions based on the row's main element's type. *
* @return */ public Graph build(){ boolean isStartNode = true; for( Tree current = root.findPreOrderNext(); current != null; current = current.findPreOrderNext() ){ Node node = nodeBuilder.createNode( current ); if( node == null ){ // The current element does not produce a node. E.g. START, END, ELSE_IF, ELSE, BRANCH continue; } current.getContent().setNode( node ); if( isStartNode ){ graph.setStartNode( node ); isStartNode = false; } else{ graph.addNode( node ); } } for( Tree current = root.findPreOrderNext(); current != null; current = current.findPreOrderNext() ){ transitionBuilder.createTransitions( graph, current ); } return graph; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy