@Test public void convertStoredDefinitionWorks() { StoredWorkflowDefinition convertedOriginal = dao.convert(original); assertThat(convertedOriginal.type, is(original.getType())); assertThat(convertedOriginal.onError, is(original.getErrorState().name())); assertThat(convertedOriginal.description, is(original.getDescription())); assertThat(convertedOriginal.states.size(), is(original.getStates().size())); for (StoredWorkflowDefinition.State convertedState : convertedOriginal.states) { boolean foundMatchingState = false; for (DummyTestState originalState : original.getStates()) { if (originalState.name().equals(convertedState.id)) { assertThat(convertedState.description, is(originalState.getDescription())); WorkflowState originalFailureTransition = original.getFailureTransitions().get(originalState.name()); assertThat(convertedState.onFailure, is(originalFailureTransition != null ? originalFailureTransition.name() : null)); List<String> originalStateTransitions = original.getAllowedTransitions().get(originalState.name()); if (originalStateTransitions != null) { assertThat(convertedState.transitions, containsElementsInAnyOrder(originalStateTransitions)); } else { assertThat(convertedState.transitions.size(), is(0)); } foundMatchingState = true; break; } } assertThat("Not found match for state " + convertedState.id, foundMatchingState, is(true)); } assertThat(convertedOriginal.supportedSignals.size(), is(original.getSupportedSignals().size())); for (StoredWorkflowDefinition.Signal convertedSignal : convertedOriginal.supportedSignals) { boolean foundMatchingSignal = false; for (Entry<Integer, String> originalSignal : original.getSupportedSignals().entrySet()) { if (originalSignal.getKey().equals(convertedSignal.value)) { assertThat(convertedSignal.description, is(originalSignal.getValue())); foundMatchingSignal = true; break; } } assertThat("Not found match for signal " + convertedSignal.value, foundMatchingSignal, is(true)); } }
StoredWorkflowDefinition convert(AbstractWorkflowDefinition<? extends WorkflowState> definition) { StoredWorkflowDefinition resp = new StoredWorkflowDefinition(); resp.type = definition.getType(); resp.description = definition.getDescription(); resp.onError = definition.getErrorState().name(); Map<String, StoredWorkflowDefinition.State> states = definition.getStates().stream().collect(toMap(WorkflowState::name, state -> new StoredWorkflowDefinition.State(state.name(), state.getType().name(), state.getDescription()))); for (Entry<String, List<String>> entry : definition.getAllowedTransitions().entrySet()) { StoredWorkflowDefinition.State state = states.get(entry.getKey()); for (String targetState : entry.getValue()) { state.transitions.add(targetState); } sort(state.transitions); } for (Entry<String, WorkflowState> entry : definition.getFailureTransitions().entrySet()) { StoredWorkflowDefinition.State state = states.get(entry.getKey()); state.onFailure = entry.getValue().name(); } resp.states = new ArrayList<>(states.values()); sort(resp.states); resp.supportedSignals = definition.getSupportedSignals().entrySet().stream().map(entry -> { Signal signal = new Signal(); signal.value = entry.getKey(); signal.description = entry.getValue(); return signal; }).sorted().collect(toList()); return resp; }
WorkflowDefinitionDao { StoredWorkflowDefinition convert(AbstractWorkflowDefinition<? extends WorkflowState> definition) { StoredWorkflowDefinition resp = new StoredWorkflowDefinition(); resp.type = definition.getType(); resp.description = definition.getDescription(); resp.onError = definition.getErrorState().name(); Map<String, StoredWorkflowDefinition.State> states = definition.getStates().stream().collect(toMap(WorkflowState::name, state -> new StoredWorkflowDefinition.State(state.name(), state.getType().name(), state.getDescription()))); for (Entry<String, List<String>> entry : definition.getAllowedTransitions().entrySet()) { StoredWorkflowDefinition.State state = states.get(entry.getKey()); for (String targetState : entry.getValue()) { state.transitions.add(targetState); } sort(state.transitions); } for (Entry<String, WorkflowState> entry : definition.getFailureTransitions().entrySet()) { StoredWorkflowDefinition.State state = states.get(entry.getKey()); state.onFailure = entry.getValue().name(); } resp.states = new ArrayList<>(states.values()); sort(resp.states); resp.supportedSignals = definition.getSupportedSignals().entrySet().stream().map(entry -> { Signal signal = new Signal(); signal.value = entry.getKey(); signal.description = entry.getValue(); return signal; }).sorted().collect(toList()); return resp; } }
WorkflowDefinitionDao { StoredWorkflowDefinition convert(AbstractWorkflowDefinition<? extends WorkflowState> definition) { StoredWorkflowDefinition resp = new StoredWorkflowDefinition(); resp.type = definition.getType(); resp.description = definition.getDescription(); resp.onError = definition.getErrorState().name(); Map<String, StoredWorkflowDefinition.State> states = definition.getStates().stream().collect(toMap(WorkflowState::name, state -> new StoredWorkflowDefinition.State(state.name(), state.getType().name(), state.getDescription()))); for (Entry<String, List<String>> entry : definition.getAllowedTransitions().entrySet()) { StoredWorkflowDefinition.State state = states.get(entry.getKey()); for (String targetState : entry.getValue()) { state.transitions.add(targetState); } sort(state.transitions); } for (Entry<String, WorkflowState> entry : definition.getFailureTransitions().entrySet()) { StoredWorkflowDefinition.State state = states.get(entry.getKey()); state.onFailure = entry.getValue().name(); } resp.states = new ArrayList<>(states.values()); sort(resp.states); resp.supportedSignals = definition.getSupportedSignals().entrySet().stream().map(entry -> { Signal signal = new Signal(); signal.value = entry.getKey(); signal.description = entry.getValue(); return signal; }).sorted().collect(toList()); return resp; } @Inject  WorkflowDefinitionDao(SQLVariants sqlVariants,
                               @NFlow NamedParameterJdbcTemplate nflowNamedParameterJdbcTemplate,
                               @NFlow ObjectMapper nflowObjectMapper,
                               ExecutorDao executorDao); }
WorkflowDefinitionDao { StoredWorkflowDefinition convert(AbstractWorkflowDefinition<? extends WorkflowState> definition) { StoredWorkflowDefinition resp = new StoredWorkflowDefinition(); resp.type = definition.getType(); resp.description = definition.getDescription(); resp.onError = definition.getErrorState().name(); Map<String, StoredWorkflowDefinition.State> states = definition.getStates().stream().collect(toMap(WorkflowState::name, state -> new StoredWorkflowDefinition.State(state.name(), state.getType().name(), state.getDescription()))); for (Entry<String, List<String>> entry : definition.getAllowedTransitions().entrySet()) { StoredWorkflowDefinition.State state = states.get(entry.getKey()); for (String targetState : entry.getValue()) { state.transitions.add(targetState); } sort(state.transitions); } for (Entry<String, WorkflowState> entry : definition.getFailureTransitions().entrySet()) { StoredWorkflowDefinition.State state = states.get(entry.getKey()); state.onFailure = entry.getValue().name(); } resp.states = new ArrayList<>(states.values()); sort(resp.states); resp.supportedSignals = definition.getSupportedSignals().entrySet().stream().map(entry -> { Signal signal = new Signal(); signal.value = entry.getKey(); signal.description = entry.getValue(); return signal; }).sorted().collect(toList()); return resp; } @Inject  WorkflowDefinitionDao(SQLVariants sqlVariants,
                               @NFlow NamedParameterJdbcTemplate nflowNamedParameterJdbcTemplate,
                               @NFlow ObjectMapper nflowObjectMapper,
                               ExecutorDao executorDao); void storeWorkflowDefinition(AbstractWorkflowDefinition<? extends WorkflowState> definition); List<StoredWorkflowDefinition> queryStoredWorkflowDefinitions(Collection<String> types); }
WorkflowDefinitionDao { StoredWorkflowDefinition convert(AbstractWorkflowDefinition<? extends WorkflowState> definition) { StoredWorkflowDefinition resp = new StoredWorkflowDefinition(); resp.type = definition.getType(); resp.description = definition.getDescription(); resp.onError = definition.getErrorState().name(); Map<String, StoredWorkflowDefinition.State> states = definition.getStates().stream().collect(toMap(WorkflowState::name, state -> new StoredWorkflowDefinition.State(state.name(), state.getType().name(), state.getDescription()))); for (Entry<String, List<String>> entry : definition.getAllowedTransitions().entrySet()) { StoredWorkflowDefinition.State state = states.get(entry.getKey()); for (String targetState : entry.getValue()) { state.transitions.add(targetState); } sort(state.transitions); } for (Entry<String, WorkflowState> entry : definition.getFailureTransitions().entrySet()) { StoredWorkflowDefinition.State state = states.get(entry.getKey()); state.onFailure = entry.getValue().name(); } resp.states = new ArrayList<>(states.values()); sort(resp.states); resp.supportedSignals = definition.getSupportedSignals().entrySet().stream().map(entry -> { Signal signal = new Signal(); signal.value = entry.getKey(); signal.description = entry.getValue(); return signal; }).sorted().collect(toList()); return resp; } @Inject  WorkflowDefinitionDao(SQLVariants sqlVariants,
                               @NFlow NamedParameterJdbcTemplate nflowNamedParameterJdbcTemplate,
                               @NFlow ObjectMapper nflowObjectMapper,
                               ExecutorDao executorDao); void storeWorkflowDefinition(AbstractWorkflowDefinition<? extends WorkflowState> definition); List<StoredWorkflowDefinition> queryStoredWorkflowDefinitions(Collection<String> types);  }