com.nitorcreations.nflow.tests.demo.DemoWorkflow Maven / Gradle / Ivy
package com.nitorcreations.nflow.tests.demo;
import static com.nitorcreations.nflow.engine.workflow.definition.NextAction.moveToState;
import static com.nitorcreations.nflow.engine.workflow.definition.NextAction.stopInState;
import static com.nitorcreations.nflow.engine.workflow.definition.WorkflowStateType.end;
import static com.nitorcreations.nflow.engine.workflow.definition.WorkflowStateType.manual;
import static com.nitorcreations.nflow.engine.workflow.definition.WorkflowStateType.normal;
import static com.nitorcreations.nflow.engine.workflow.definition.WorkflowStateType.start;
import org.springframework.stereotype.Component;
import com.nitorcreations.nflow.engine.workflow.definition.NextAction;
import com.nitorcreations.nflow.engine.workflow.definition.StateExecution;
import com.nitorcreations.nflow.engine.workflow.definition.WorkflowDefinition;
import com.nitorcreations.nflow.engine.workflow.definition.WorkflowState;
import com.nitorcreations.nflow.engine.workflow.definition.WorkflowStateType;
@Component
public class DemoWorkflow extends WorkflowDefinition {
public static final String DEMO_WORKFLOW_TYPE = "demo";
public static enum State implements WorkflowState {
begin(start), process(normal), done(end), error(manual);
private WorkflowStateType type;
private State(WorkflowStateType type) {
this.type = type;
}
@Override
public WorkflowStateType getType() {
return type;
}
@Override
public String getName() {
return name();
}
@Override
public String getDescription() {
return name();
}
}
public DemoWorkflow() {
super(DEMO_WORKFLOW_TYPE, State.begin, State.error);
permit(State.begin, State.process);
permit(State.process, State.done);
}
public NextAction begin(StateExecution execution) {
return moveToState(State.process, "Go to process state");
}
public NextAction process(StateExecution execution) {
return stopInState(State.done, "Go to done state");
}
}