/** * Gets the best descriptive name. * * @return the best descriptive name, not null */ public String getBestName() { Security security = getTarget(); ObjectId objectId = getObjectId(); ExternalIdBundle bundle = getExternalId(); if (security != null) { // Try to retrieve the security's assigned name String name = security.getName(); if (StringUtils.isNotBlank(name)) { return name; } bundle = security.getExternalIdBundle(); } if (bundle != null && bundle.size() > 0) { if (bundle.getValue(ExternalSchemes.BLOOMBERG_TICKER) != null) { return bundle.getValue(ExternalSchemes.BLOOMBERG_TICKER); } else if (bundle.getValue(ExternalSchemes.RIC) != null) { return bundle.getValue(ExternalSchemes.RIC); } else if (bundle.getValue(ExternalSchemes.ACTIVFEED_TICKER) != null) { return bundle.getValue(ExternalSchemes.ACTIVFEED_TICKER); } else { return bundle.getExternalIds().iterator().next().getValue(); } } if (objectId != null) { return objectId.toString(); } return ""; }
/** * Resolves the security using a security source. * * @param source the source to use to resolve, not null * @param versionCorrection the version-correction, not null * @return the resolved security, not null * @throws DataNotFoundException if the security could not be resolved * @throws RuntimeException if an error occurs while resolving */ public Security resolve(SecuritySource source, VersionCorrection versionCorrection) { ObjectId objectId = getObjectId(); if (objectId != null) { Security target = source.getSecurity(objectId, versionCorrection); setTarget(target); return target; } ExternalIdBundle bundle = getExternalId(); if (bundle.size() > 0) { Security target = source.getSecurity(bundle, versionCorrection); if (target != null) { setTarget(target); return target; } } throw new DataNotFoundException("Unable to resolve security: " + getBestName()); }