-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support loading workflow definitions from database if nflow.definitio…
…n.load=true is set
- Loading branch information
Showing
2 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...gine/src/main/java/io/nflow/engine/internal/workflow/StoredWorkflowDefinitionWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.nflow.engine.internal.workflow; | ||
|
||
import io.nflow.engine.internal.workflow.StoredWorkflowDefinition.State; | ||
import io.nflow.engine.workflow.definition.WorkflowDefinition; | ||
import io.nflow.engine.workflow.definition.WorkflowSettings; | ||
import io.nflow.engine.workflow.definition.WorkflowState; | ||
import io.nflow.engine.workflow.definition.WorkflowStateType; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import static io.nflow.engine.workflow.definition.WorkflowStateType.start; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
public class StoredWorkflowDefinitionWrapper extends WorkflowDefinition { | ||
public StoredWorkflowDefinitionWrapper(StoredWorkflowDefinition stored) { | ||
super(stored.type, getInitialState(stored), getErrorState(stored), new WorkflowSettings.Builder().build(), null, allStates(stored)); | ||
setDescription(stored.description); | ||
} | ||
|
||
private static Collection<WorkflowState> allStates(StoredWorkflowDefinition stored) { | ||
return stored.states.stream().map(StoredWorkflowDefinitionWrapper::toState).collect(toList()); | ||
} | ||
|
||
private static WorkflowState getInitialState(StoredWorkflowDefinition stored) { | ||
for (State state : stored.states) { | ||
if (start.name().equals(state.type)) { | ||
return toState(state); | ||
} | ||
} | ||
throw new IllegalStateException("Could not find initial state for " + stored); | ||
} | ||
|
||
private static WorkflowState toState(StoredWorkflowDefinition.State state) { | ||
return new io.nflow.engine.workflow.curated.State(state.id, WorkflowStateType.valueOf(state.type), state.description); | ||
} | ||
|
||
private static WorkflowState getErrorState(StoredWorkflowDefinition stored) { | ||
for (State state : stored.states) { | ||
if (stored.onError.equals(state.id)) { | ||
return toState(state); | ||
} | ||
} | ||
throw new IllegalStateException("Could not find error state for " + stored); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters