Skip to content

Files

Latest commit

596d76f · Jun 23, 2019

History

History

sample02

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jan 12, 2019
Jan 27, 2019
Dec 25, 2018
Dec 25, 2018
Jun 23, 2019

Passing data between steps sample

Illustrates how to define a data class for your workflow and wire it's properties up to the inputs and outputs of steps.

First, we define a class to hold data for our workflow.

public class MyData {    
    public int value1;
    public int value2;
    public int value3;
}

Then we create a step with inputs and outputs, by simply exposing public properties.

public class AddNumbers implements StepBody {

    public int number1;
    public int number2;
    public int answer;
    
    @Override
    public ExecutionResult run(StepExecutionContext context) {
        answer = number1 + number2;
        return ExecutionResult.next();
    }    
}

Then we put it all together in a workflow.

public class DataWorkflow implements Workflow<MyData> {

    @Override
    public void build(WorkflowBuilder<MyData> builder) {        
        builder
            .startsWith(AddNumbers.class)  
                .input((step, data) -> step.number1 = data.value1)
                .input((step, data) -> step.number2 = data.value2)
                .output((step, data) -> data.value3 = step.answer)
            .then(DisplayAnswer.class)
                .input((step, data) -> step.answer = data.value3);
    }

    ...    
}