if (security instanceof CreditDefaultSwapOptionSecurity) {
final CreditDefaultSwapOptionSecurity cdsOption = (CreditDefaultSwapOptionSecurity) security;
final ExternalId underlyingId = cdsOption.getUnderlyingId();
final Security underlying = _securitySource.getSingle(underlyingId.toBundle());
final String redCode = ((CreditDefaultSwapSecurity) underlying).getReferenceEntity().getValue();
final Organization organisation = _organizationSource.getOrganizationByRedCode(redCode);
return organisation.getObligor().getObligorShortName();
} else if (security instanceof CreditDefaultSwapIndexSecurity) {
final CreditDefaultSwapIndexSecurity cdsIndex = (CreditDefaultSwapIndexSecurity) security;
final CreditDefaultSwapIndexDefinitionSecurity definition = (CreditDefaultSwapIndexDefinitionSecurity) _securitySource.getSingle(ExternalIdBundle.of(cdsIndex.getReferenceEntity()));
return definition.getName();
} else if (security instanceof CreditDefaultSwapSecurity) {
final AbstractCreditDefaultSwapSecurity cds = (AbstractCreditDefaultSwapSecurity) security;
final String redCode = cds.getReferenceEntity().getValue();
final Organization organisation = _organizationSource.getOrganizationByRedCode(redCode);
if (organisation != null) {
return organisation.getObligor().getObligorShortName();
} else {
return redCode;
}
}