public ReferenceDataResult ensureReferenceDataAvailability(final List<PipelineReference> pipelineReferences,
                                                               final LookupIdentifier lookupIdentifier,
                                                               final ReferenceDataResult result) {

        LOGGER.debug("ensureReferenceDataAvailability({}, {})", lookupIdentifier, pipelineReferences);

        // Do we have a nested map e.g a map of 'USER_ID_TO_MANAGER/USER_ID_TO_LOCATION' to get the location of a
        // user's manager using a chained lookup
        if (lookupIdentifier.isMapNested()) {
            LOGGER.trace("lookupIdentifier is nested {}", lookupIdentifier);

            // Look up the KV then use that to recurse
            doGetValue(pipelineReferences, lookupIdentifier, result);

            final Optional<RefDataValue> optValue = result.getRefDataValueProxy()
                    .flatMap(RefDataValueProxy::supplyValue);
            // This is a nested map so we are expecting the value of the first map to be a simple
            // string so we can use it as the key for the next map. The next map could also be nested.

            if (optValue.isEmpty()) {
                LOGGER.trace("sub-map not found for {}", lookupIdentifier);
                // map broken ... no link found
                result.logSimpleTemplate(Severity.WARNING, "No map found for '{}'", lookupIdentifier);
            } else {
                final RefDataValue refDataValue = optValue.get();
                try {
                    final String nextKey = ((StringValue) refDataValue).getValue();
                    LOGGER.trace("Found value to use as next key {}", nextKey);

                    logMapLocations(result);

                    // use the value from this lookup as the key for the nested map
                    final LookupIdentifier nestedIdentifier = lookupIdentifier.getNestedLookupIdentifier(nextKey);

                    // As we are recursing, make sure the result is in a clean state for the next level of
                    // the recursion
                    result.setCurrentLookupIdentifier(nestedIdentifier);

                    result.logLazyTemplate(
                            Severity.INFO,
                            "Nested lookup using previous lookup value as new key: '{}' - " +
                            "(primary map: {}, secondary map: {}, nested lookup: {})",
                            () -> Arrays.asList(
                                    nextKey,
                                    nestedIdentifier.getPrimaryMapName(),
                                    Objects.requireNonNullElse(nestedIdentifier.getSecondaryMapName(), ""),
                                    nestedIdentifier.isMapNested()));

                    // Recurse with the nested lookup
                    ensureReferenceDataAvailability(pipelineReferences, nestedIdentifier, result);
                } catch (ClassCastException e) {
                    result.logLazyTemplate(Severity.ERROR,
                            "Value is the wrong type, expected: {}, found: {}",
                            () -> Arrays.asList(StringValue.class.getName(),
                                    refDataValue.getClass().getName()));
                }
            }
        } else {
            LOGGER.trace("lookupIdentifier is not nested {}", lookupIdentifier);
            // non-nested map so just do a lookup
            doGetValue(pipelineReferences, lookupIdentifier, result);
        }
        // Return the passed result object to aid with mocking in tests
        return result;
    }
<p>
Given a {@link LookupIdentifier} and a list of ref data pipelines, ensure that
the data required to perform the lookup is in the ref store. This method will not
perform the lookup, instead it will populate the {@link ReferenceDataResult} with
a proxy object that can later be used to do the lookup.
</p>

@param pipelineReferences The references to look for reference data in.
@param lookupIdentifier   The identifier to lookup in the reference data
@param result             The reference result object containing the proxy object for performing the lookup
@return The passed result object
stroom-pipeline/src/main/java/stroom/pipeline/refdata/ReferenceData.java