package wf.servitor.common.workflow import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder import wf.servitor.common.workflow.step.* import java.io.Serializable @Suppress("unused") @JsonDeserialize(builder = Step.Builder::class) interface Step : Serializable { val name: String fun getChild(index: Int): Step? { return null } fun children() = 0 fun getScript(): String? = null fun next(result: Any?): StepContinuation = StepContinuation.Continue @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "with") class Builder { var name: String = "" var `if`: String? = null var `do`: String? = null var then: String? = null var `else`: String? = null var options: List? = null var collect: List? = null fun withName(value: String) { this.name = value } fun withIf(value: String) { this.`if` = value } fun withDo(value: String) { this.`do` = value } fun withThen(value: String) { this.then = value } fun withElse(value: String) { this.`else` = value } fun withOptions(value: List) { this.options = value } fun withCollect(value: List) { this.collect = value } fun build(): Step { val `if` = this.`if` val `do` = this.`do` if (`if` != null) { if (`do` != null) { return IfActionStep(`if`, `do`, name) } val then = then val `else` = `else` if (then != null || `else` != null) { return IfJumpStep(`if`, then, `else`, name) } error("Step missing 'then', 'else' or 'do'") } val options = options if (options != null) { return OptionsStep(options, name) } val collect = collect if (collect != null) { return CollectStep(collect, name) } if (`do` != null) { return ActionStep(`do`, name) } error("No matching type of step could be found") } } }