private SteppingResult step(final StepType direction,
                                final int steps,
                                final PipelineStepRequest.Builder requestBuilder,
                                final SteppingResult existingResponse) {
        SteppingResult newResponse = existingResponse;

        for (int i = 0; i < steps; i++) {
            requestBuilder.stepType(direction);
            final SteppingResult stepResponse = steppingService.step(requestBuilder.build());

            if (stepResponse.getGeneralErrors() != null && stepResponse.getGeneralErrors().size() > 0) {
                throw new RuntimeException(stepResponse.getGeneralErrors().iterator().next());
            }

            if (stepResponse.isFoundRecord()) {
                final SharedStepData stepData = stepResponse.getStepData();
                for (final String elementId : stepData.getElementMap().keySet()) {
                    String input = null;
                    String output = null;
//                    Indicators codeIndicators = null;
//                    Indicators outputIndicators = null;
                    Indicators indicators = null;

                    // Get existing data.
                    if (newResponse != null) {
                        final SharedStepData existingStepData = newResponse.getStepData();
                        if (existingStepData != null) {
                            final SharedElementData existingElementData = existingStepData.getElementData(elementId);
                            if (existingElementData != null) {
                                input = existingElementData.getInput();
                                output = existingElementData.getOutput();
//                                codeIndicators = existingElementData.getCodeIndicators();
//                                outputIndicators = existingElementData.getOutputIndicators();
                                indicators = existingElementData.getIndicators();
                            }
                        }
                    }

                    // Append new data.
                    final SharedElementData elementData = stepData.getElementData(elementId);
                    if (elementData != null) {
                        if (input == null) {
                            input = elementData.getInput();
                        } else {
                            input += "\n" + elementData.getInput();
                        }

                        if (output == null) {
                            output = elementData.getOutput();
                        } else {
                            output += "\n" + elementData.getOutput();
                        }

                        if (indicators == null) {
                            indicators = elementData.getIndicators();
                        } else {
                            indicators.addAll(elementData.getIndicators());
                        }

//                        if (outputIndicators == null) {
//                            outputIndicators = elementData.getOutputIndicators();
//                        } else {
//                            outputIndicators.addAll(elementData.getOutputIndicators());
//                        }

                        final SharedElementData newElementData = new SharedElementData(
                                input, output, indicators, elementData.isFormatInput(), elementData.isFormatOutput());
                        SharedStepData newStepData = newResponse.getStepData();
                        if (newStepData == null) {
                            newStepData = new SharedStepData(stepResponse.getStepData().getSourceLocation(),
                                    new HashMap<>());
                        }
                        newStepData.getElementMap().put(elementId, newElementData);
                        newResponse = new SteppingResult(
                                null,
                                stepResponse.getStepFilterMap(),
                                stepResponse.getProgressLocation(),
                                stepResponse.getFoundLocation(),
                                newStepData,
                                stepResponse.getCurrentStreamOffset(),
                                stepResponse.isFoundRecord(),
                                null,
                                stepResponse.isSegmentedData(),
                                true);
                    }
                }

                // Set the request to use the last response location to move on
                // from.
                requestBuilder.stepLocation(stepResponse.getFoundLocation());
            }
        }

        return newResponse;
    }
Gets the next task to be processed.

@return The next task or null if there are currently no more tasks.
stroom-app/src/test/java/stroom/pipeline/task/TranslationTest.java