You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.4 KiB
Kotlin
95 lines
2.4 KiB
Kotlin
4 years ago
|
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<OptionsStep.Option>? = null
|
||
|
var collect: List<Step>? = 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<OptionsStep.Option>) {
|
||
|
this.options = value
|
||
|
}
|
||
|
|
||
|
fun withCollect(value: List<Step>) {
|
||
|
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")
|
||
|
}
|
||
|
}
|
||
|
}
|