Map<String, ReferenceData> cachedResults = loadFieldValues(identifiers);
Map<Set<String>, Set<String>> identifiersByFields = Maps.newHashMap();
for (String identifier : identifiers) {
ReferenceData cachedResult = cachedResults.get(identifier);
if (cachedResult == null) {
continue; // nothing to refresh
}
Set<String> fields = new HashSet<String>();
fields.addAll(cachedResult.getFieldValues().getAllFieldNames());
fields.addAll(getNotAvailableFields(cachedResult));
fields.remove(FIELD_NOT_AVAILABLE_NAME);
Set<String> secsForTheseFields = identifiersByFields.get(fields);
if (secsForTheseFields == null) {
secsForTheseFields = new HashSet<String>();
identifiersByFields.put(fields, secsForTheseFields);
}
secsForTheseFields.add(identifier);
}
for (Entry<Set<String>, Set<String>> entry : identifiersByFields.entrySet()) {
Set<String> identifiersForTheseFields = entry.getValue();
Set<String> fields = entry.getKey();
ReferenceDataProviderGetRequest underlyingRequest = ReferenceDataProviderGetRequest.createGet(identifiersForTheseFields, fields, false);
ReferenceDataProviderGetResult underlyingResult = _underlying.getReferenceData(underlyingRequest);
for (ReferenceData refData : underlyingResult.getReferenceData()) {
ReferenceData previousResult = cachedResults.get(refData.getIdentifier());
ReferenceData resolvedResult = getCombinedResult(fields, new ReferenceData(refData.getIdentifier()), refData);
if (differentCachedResult(previousResult, resolvedResult)) {
saveFieldValues(resolvedResult);
}
}
}