Slight refactoring

This commit is contained in:
Eugene Zadyra
2018-07-04 11:00:46 +02:00
parent 1ac00eaa06
commit 55c12c0e6c

View File

@@ -27,7 +27,11 @@ trait Conversation[D] extends Actor with Domain[D] with Logger {
override def receive: Receive = {
case InitConversation => init()
case StartConversation | ContinueConversation =>
case StartConversation | ContinueConversation => execute()
case any => makeTransition(any)
}
def execute(): Unit = {
try {
currentStep match {
case qa: QuestionAnswer => qa.question.questionFn(currentData)
@@ -39,14 +43,6 @@ trait Conversation[D] extends Actor with Domain[D] with Logger {
} catch {
case NonFatal(ex) => error("Step execution failed", ex)
}
case any => makeTransition(any)
}
private def moveToNextStep(nextStep: NextStep): Unit = {
currentStep = nextStep.step
nextStep.data.foreach { data =>
currentData = data
}
}
private def makeTransition(any: Any): Unit = {
@@ -73,6 +69,13 @@ trait Conversation[D] extends Actor with Domain[D] with Logger {
}
}
private def moveToNextStep(nextStep: NextStep): Unit = {
currentStep = nextStep.step
nextStep.data.foreach { data =>
currentData = data
}
}
private def init(): Unit = {
require(startWithStep != null, "Entry point must be defined")
currentStep = startWithStep