Set<String> bbgKeys = new HashSet<String>();
Map<String, Collection<ExternalIdBundle>> bbgKey2Bundle = new HashMap<String, Collection<ExternalIdBundle>>();
for (ExternalIdBundle bundle : bundles) {
String bbgUniqueId = null;
ExternalId preferredIdentifier = BloombergDomainIdentifierResolver.resolvePreferredIdentifier(bundle);
if (preferredIdentifier != null) {
if (!preferredIdentifier.getScheme().equals(ExternalSchemes.BLOOMBERG_BUID)) {
String bloombergKey = BloombergDomainIdentifierResolver.toBloombergKey(preferredIdentifier);
bbgKeys.add(bloombergKey);
Collection<ExternalIdBundle> bundlesForKey = bbgKey2Bundle.get(bloombergKey);
if (bundlesForKey == null) {
bundlesForKey = new ArrayList<ExternalIdBundle>();
bbgKey2Bundle.put(bloombergKey, bundlesForKey);
}
bundlesForKey.add(bundle);
} else {
bbgUniqueId = preferredIdentifier.getValue();
result.put(bundle, ExternalSchemes.bloombergBuidSecurityId(bbgUniqueId));
}
} else {
s_logger.info("Unable to identify any Bloomberg compatible identifier for {}", bundle);
result.put(bundle, null);
}
}
Map<String, String> bbgKey2BbgUniqueId = ReferenceDataProviderUtils.getBloombergUniqueIDs(bbgKeys, getReferenceDataProvider());
for (String bbgKey : bbgKey2Bundle.keySet()) {
String bbgUniqueId = bbgKey2BbgUniqueId.get(bbgKey);
ExternalId identifier;
if (bbgUniqueId == null) {
identifier = null;
} else {
identifier = ExternalSchemes.bloombergBuidSecurityId(bbgUniqueId);
}