@Test public void convertStoredDefinitionWorks() { StoredWorkflowDefinition stored = new StoredWorkflowDefinition(); stored.description = "desc"; stored.onError = "errorState"; stored.type = "storedDefinition"; StoredWorkflowDefinition.State storedState = new StoredWorkflowDefinition.State("first", "normal", "first state desc"); stored.states = asList(storedState); StoredWorkflowDefinition.Signal storedSignal = new StoredWorkflowDefinition.Signal(); storedSignal.value = 1; storedSignal.description = "one"; stored.supportedSignals = asList(storedSignal); ListWorkflowDefinitionResponse resp = converter.convert(stored); assertThat(resp.description, is(stored.description)); assertThat(resp.onError, is(stored.onError)); assertThat(resp.states.length, is(1)); assertThat(resp.states[0].description, is(storedState.description)); assertThat(resp.states[0].type, is(storedState.type)); assertThat(resp.states[0].id, is(storedState.id)); assertThat(resp.supportedSignals[0].value, is(storedSignal.value)); assertThat(resp.supportedSignals[0].description, is(storedSignal.description)); }
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "cast is safe") public ListWorkflowDefinitionResponse convert(AbstractWorkflowDefinition<? extends WorkflowState> definition) { ListWorkflowDefinitionResponse resp = new ListWorkflowDefinitionResponse(); resp.type = definition.getType(); resp.name = definition.getName(); resp.description = definition.getDescription(); resp.onError = definition.getErrorState().name(); Map<String, State> states = new LinkedHashMap<>(definition.getStates().size() * 2); for (WorkflowState state : definition.getStates()) { states.put(state.name(), new State(state.name(), state.getType().name(), state.getDescription())); } for (Entry<String, List<String>> entry : definition.getAllowedTransitions().entrySet()) { State state = states.get(entry.getKey()); for(String targetState : entry.getValue()) { state.transitions.add(targetState); } } for (Entry<String, WorkflowState> entry : definition.getFailureTransitions().entrySet()) { State state = states.get(entry.getKey()); state.onFailure = entry.getValue().name(); } Collection<State> values = states.values(); resp.states = values.toArray(new State[values.size()]); WorkflowSettings workflowSettings = definition.getSettings(); TransitionDelays transitionDelays = new TransitionDelays(); transitionDelays.immediate = workflowSettings.immediateTransitionDelay; transitionDelays.waitShort = workflowSettings.shortTransitionDelay; transitionDelays.minErrorWait = workflowSettings.minErrorTransitionDelay; transitionDelays.maxErrorWait = workflowSettings.maxErrorTransitionDelay; Settings settings = new Settings(); settings.transitionDelaysInMilliseconds = transitionDelays; settings.maxRetries = workflowSettings.maxRetries; settings.historyDeletableAfter = workflowSettings.historyDeletableAfter; settings.defaultPriority = workflowSettings.defaultPriority; resp.settings = settings; resp.supportedSignals = definition.getSupportedSignals().entrySet().stream().map(entry -> { Signal signal = new Signal(); signal.value = entry.getKey(); signal.description = entry.getValue(); return signal; }).toArray(size -> new Signal[size]); return resp; }
ListWorkflowDefinitionConverter { @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "cast is safe") public ListWorkflowDefinitionResponse convert(AbstractWorkflowDefinition<? extends WorkflowState> definition) { ListWorkflowDefinitionResponse resp = new ListWorkflowDefinitionResponse(); resp.type = definition.getType(); resp.name = definition.getName(); resp.description = definition.getDescription(); resp.onError = definition.getErrorState().name(); Map<String, State> states = new LinkedHashMap<>(definition.getStates().size() * 2); for (WorkflowState state : definition.getStates()) { states.put(state.name(), new State(state.name(), state.getType().name(), state.getDescription())); } for (Entry<String, List<String>> entry : definition.getAllowedTransitions().entrySet()) { State state = states.get(entry.getKey()); for(String targetState : entry.getValue()) { state.transitions.add(targetState); } } for (Entry<String, WorkflowState> entry : definition.getFailureTransitions().entrySet()) { State state = states.get(entry.getKey()); state.onFailure = entry.getValue().name(); } Collection<State> values = states.values(); resp.states = values.toArray(new State[values.size()]); WorkflowSettings workflowSettings = definition.getSettings(); TransitionDelays transitionDelays = new TransitionDelays(); transitionDelays.immediate = workflowSettings.immediateTransitionDelay; transitionDelays.waitShort = workflowSettings.shortTransitionDelay; transitionDelays.minErrorWait = workflowSettings.minErrorTransitionDelay; transitionDelays.maxErrorWait = workflowSettings.maxErrorTransitionDelay; Settings settings = new Settings(); settings.transitionDelaysInMilliseconds = transitionDelays; settings.maxRetries = workflowSettings.maxRetries; settings.historyDeletableAfter = workflowSettings.historyDeletableAfter; settings.defaultPriority = workflowSettings.defaultPriority; resp.settings = settings; resp.supportedSignals = definition.getSupportedSignals().entrySet().stream().map(entry -> { Signal signal = new Signal(); signal.value = entry.getKey(); signal.description = entry.getValue(); return signal; }).toArray(size -> new Signal[size]); return resp; } }
ListWorkflowDefinitionConverter { @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "cast is safe") public ListWorkflowDefinitionResponse convert(AbstractWorkflowDefinition<? extends WorkflowState> definition) { ListWorkflowDefinitionResponse resp = new ListWorkflowDefinitionResponse(); resp.type = definition.getType(); resp.name = definition.getName(); resp.description = definition.getDescription(); resp.onError = definition.getErrorState().name(); Map<String, State> states = new LinkedHashMap<>(definition.getStates().size() * 2); for (WorkflowState state : definition.getStates()) { states.put(state.name(), new State(state.name(), state.getType().name(), state.getDescription())); } for (Entry<String, List<String>> entry : definition.getAllowedTransitions().entrySet()) { State state = states.get(entry.getKey()); for(String targetState : entry.getValue()) { state.transitions.add(targetState); } } for (Entry<String, WorkflowState> entry : definition.getFailureTransitions().entrySet()) { State state = states.get(entry.getKey()); state.onFailure = entry.getValue().name(); } Collection<State> values = states.values(); resp.states = values.toArray(new State[values.size()]); WorkflowSettings workflowSettings = definition.getSettings(); TransitionDelays transitionDelays = new TransitionDelays(); transitionDelays.immediate = workflowSettings.immediateTransitionDelay; transitionDelays.waitShort = workflowSettings.shortTransitionDelay; transitionDelays.minErrorWait = workflowSettings.minErrorTransitionDelay; transitionDelays.maxErrorWait = workflowSettings.maxErrorTransitionDelay; Settings settings = new Settings(); settings.transitionDelaysInMilliseconds = transitionDelays; settings.maxRetries = workflowSettings.maxRetries; settings.historyDeletableAfter = workflowSettings.historyDeletableAfter; settings.defaultPriority = workflowSettings.defaultPriority; resp.settings = settings; resp.supportedSignals = definition.getSupportedSignals().entrySet().stream().map(entry -> { Signal signal = new Signal(); signal.value = entry.getKey(); signal.description = entry.getValue(); return signal; }).toArray(size -> new Signal[size]); return resp; }  }
ListWorkflowDefinitionConverter { @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "cast is safe") public ListWorkflowDefinitionResponse convert(AbstractWorkflowDefinition<? extends WorkflowState> definition) { ListWorkflowDefinitionResponse resp = new ListWorkflowDefinitionResponse(); resp.type = definition.getType(); resp.name = definition.getName(); resp.description = definition.getDescription(); resp.onError = definition.getErrorState().name(); Map<String, State> states = new LinkedHashMap<>(definition.getStates().size() * 2); for (WorkflowState state : definition.getStates()) { states.put(state.name(), new State(state.name(), state.getType().name(), state.getDescription())); } for (Entry<String, List<String>> entry : definition.getAllowedTransitions().entrySet()) { State state = states.get(entry.getKey()); for(String targetState : entry.getValue()) { state.transitions.add(targetState); } } for (Entry<String, WorkflowState> entry : definition.getFailureTransitions().entrySet()) { State state = states.get(entry.getKey()); state.onFailure = entry.getValue().name(); } Collection<State> values = states.values(); resp.states = values.toArray(new State[values.size()]); WorkflowSettings workflowSettings = definition.getSettings(); TransitionDelays transitionDelays = new TransitionDelays(); transitionDelays.immediate = workflowSettings.immediateTransitionDelay; transitionDelays.waitShort = workflowSettings.shortTransitionDelay; transitionDelays.minErrorWait = workflowSettings.minErrorTransitionDelay; transitionDelays.maxErrorWait = workflowSettings.maxErrorTransitionDelay; Settings settings = new Settings(); settings.transitionDelaysInMilliseconds = transitionDelays; settings.maxRetries = workflowSettings.maxRetries; settings.historyDeletableAfter = workflowSettings.historyDeletableAfter; settings.defaultPriority = workflowSettings.defaultPriority; resp.settings = settings; resp.supportedSignals = definition.getSupportedSignals().entrySet().stream().map(entry -> { Signal signal = new Signal(); signal.value = entry.getKey(); signal.description = entry.getValue(); return signal; }).toArray(size -> new Signal[size]); return resp; }  @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "cast is safe") ListWorkflowDefinitionResponse convert(AbstractWorkflowDefinition<? extends WorkflowState> definition); ListWorkflowDefinitionResponse convert(StoredWorkflowDefinition storedDefinition); }
ListWorkflowDefinitionConverter { @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "cast is safe") public ListWorkflowDefinitionResponse convert(AbstractWorkflowDefinition<? extends WorkflowState> definition) { ListWorkflowDefinitionResponse resp = new ListWorkflowDefinitionResponse(); resp.type = definition.getType(); resp.name = definition.getName(); resp.description = definition.getDescription(); resp.onError = definition.getErrorState().name(); Map<String, State> states = new LinkedHashMap<>(definition.getStates().size() * 2); for (WorkflowState state : definition.getStates()) { states.put(state.name(), new State(state.name(), state.getType().name(), state.getDescription())); } for (Entry<String, List<String>> entry : definition.getAllowedTransitions().entrySet()) { State state = states.get(entry.getKey()); for(String targetState : entry.getValue()) { state.transitions.add(targetState); } } for (Entry<String, WorkflowState> entry : definition.getFailureTransitions().entrySet()) { State state = states.get(entry.getKey()); state.onFailure = entry.getValue().name(); } Collection<State> values = states.values(); resp.states = values.toArray(new State[values.size()]); WorkflowSettings workflowSettings = definition.getSettings(); TransitionDelays transitionDelays = new TransitionDelays(); transitionDelays.immediate = workflowSettings.immediateTransitionDelay; transitionDelays.waitShort = workflowSettings.shortTransitionDelay; transitionDelays.minErrorWait = workflowSettings.minErrorTransitionDelay; transitionDelays.maxErrorWait = workflowSettings.maxErrorTransitionDelay; Settings settings = new Settings(); settings.transitionDelaysInMilliseconds = transitionDelays; settings.maxRetries = workflowSettings.maxRetries; settings.historyDeletableAfter = workflowSettings.historyDeletableAfter; settings.defaultPriority = workflowSettings.defaultPriority; resp.settings = settings; resp.supportedSignals = definition.getSupportedSignals().entrySet().stream().map(entry -> { Signal signal = new Signal(); signal.value = entry.getKey(); signal.description = entry.getValue(); return signal; }).toArray(size -> new Signal[size]); return resp; }  @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "cast is safe") ListWorkflowDefinitionResponse convert(AbstractWorkflowDefinition<? extends WorkflowState> definition); ListWorkflowDefinitionResponse convert(StoredWorkflowDefinition storedDefinition);  }