Skip to content

Commit

Permalink
search: properly pluralize Business.Identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Jan 14, 2025
1 parent abfbc2a commit dae7826
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion internal/integrity/ofac_csl_us_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestIntegrity_OFAC_US_CSL(t *testing.T) {
require.ElementsMatch(t, ofacEntity.Business.AltNames, cslUSEntity.Business.AltNames)
require.Equal(t, ofacEntity.Business.Created, cslUSEntity.Business.Created)
require.Equal(t, ofacEntity.Business.Dissolved, cslUSEntity.Business.Dissolved)
require.ElementsMatch(t, ofacEntity.Business.Identifier, cslUSEntity.Business.Identifier)
require.ElementsMatch(t, ofacEntity.Business.Identifiers, cslUSEntity.Business.Identifiers)

// Common Fields
require.Equal(t, ofacEntity.Contact, cslUSEntity.Contact)
Expand Down
4 changes: 2 additions & 2 deletions pkg/csl_us/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func mapBusiness(src ENHANCED_XML.EntitiesEntity) *search.Business {

// Map business identifiers
if src.IdentityDocuments != nil {
business.Identifier = mapIdentifiers(src.IdentityDocuments)
business.Identifiers = mapIdentifiers(src.IdentityDocuments)
}

return business
Expand Down Expand Up @@ -230,7 +230,7 @@ func mapOrganization(src ENHANCED_XML.EntitiesEntity) *search.Organization {

// Map organization identifiers
if src.IdentityDocuments != nil {
org.Identifier = mapIdentifiers(src.IdentityDocuments)
org.Identifiers = mapIdentifiers(src.IdentityDocuments)
}

return org
Expand Down
2 changes: 1 addition & 1 deletion pkg/ofac/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func ToEntity(sdn SDN, addresses []Address, comments []SDNComments, altIds []Alt
out.Business.Created = findDateStamp(findMatchingRemarks(remarks, "Organization Established Date"))
// out.Business.Dissolved = findDateStamp(findMatchingRemarks(remarks, "TODO(adam)"))

out.Business.Identifier = makeIdentifiers(remarks, []string{
out.Business.Identifiers = makeIdentifiers(remarks, []string{
"Branch Unit Number",
"Business Number",
"Business Registration Document",
Expand Down
8 changes: 4 additions & 4 deletions pkg/ofac/mapper_business_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestMapperBusiness__FromSource(t *testing.T) {
{Name: "Company Number", Country: "Czech Republic", Identifier: "07486049"},
{Name: "Legal Entity Number", Country: "Czech Republic", Identifier: "5299007NTWCC3U23WM81"},
}
require.ElementsMatch(t, expectedIdentifiers, business.Identifier)
require.ElementsMatch(t, expectedIdentifiers, business.Identifiers)

expectedContact := search.ContactInfo{
Websites: []string{"suex.io"},
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestMapperBusiness__FromSource(t *testing.T) {
{Name: "Business Registration Number", Country: "Russia", Identifier: "1207700248030"},
{Name: "Tax ID No.", Country: "Russia", Identifier: "9709063550"},
}
require.ElementsMatch(t, expectedIdentifiers, business.Identifier)
require.ElementsMatch(t, expectedIdentifiers, business.Identifiers)

expectedContact := search.ContactInfo{
Websites: []string{"www.dialog.info", "www.dialog-regions.ru"},
Expand Down Expand Up @@ -173,10 +173,10 @@ func TestMapper__CompleteBusiness(t *testing.T) {

require.NotNil(t, e.Business)
require.Equal(t, "ACME CORPORATION", e.Business.Name)
require.Len(t, e.Business.Identifier, 3)
require.Len(t, e.Business.Identifiers, 3)

// Sort the identifiers to ensure consistent ordering for tests
identifiers := e.Business.Identifier
identifiers := e.Business.Identifiers
sort.Slice(identifiers, func(i, j int) bool {
return identifiers[i].Country < identifiers[j].Country
})
Expand Down
20 changes: 10 additions & 10 deletions pkg/search/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ var (
)

type Business struct {
Name string `json:"name"`
AltNames []string `json:"altNames"`
Created *time.Time `json:"created"`
Dissolved *time.Time `json:"dissolved"`
Identifier []Identifier `json:"identifier"`
Name string `json:"name"`
AltNames []string `json:"altNames"`
Created *time.Time `json:"created"`
Dissolved *time.Time `json:"dissolved"`
Identifiers []Identifier `json:"identifiers"`
}

// Identifier
Expand All @@ -140,11 +140,11 @@ type Identifier struct {
//
// TODO(adam): https://www.opensanctions.org/reference/#schema.Organization
type Organization struct {
Name string `json:"name"`
AltNames []string `json:"altNames"`
Created *time.Time `json:"created"`
Dissolved *time.Time `json:"dissolved"`
Identifier []Identifier `json:"identifier"`
Name string `json:"name"`
AltNames []string `json:"altNames"`
Created *time.Time `json:"created"`
Dissolved *time.Time `json:"dissolved"`
Identifiers []Identifier `json:"identifier"`
}

type Aircraft struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/search/similarity.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func countBusinessFields(b *Business) int {
if b.Created != nil {
count++
}
if len(b.Identifier) > 0 {
if len(b.Identifiers) > 0 {
count++
}

Expand All @@ -394,7 +394,7 @@ func countOrganizationFields(o *Organization) int {
if o.Created != nil {
count++
}
if len(o.Identifier) > 0 {
if len(o.Identifiers) > 0 {
count++
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/search/similarity_exact.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ func compareBusinessExactIDs(w io.Writer, query *Business, index *Business, weig
hasMatch := false

// Business Registration/Tax IDs
if len(query.Identifier) > 0 && len(index.Identifier) > 0 {
if len(query.Identifiers) > 0 && len(index.Identifiers) > 0 {
fieldsCompared++
totalWeight += 15.0
for _, qID := range query.Identifier {
for _, iID := range index.Identifier {
for _, qID := range query.Identifiers {
for _, iID := range index.Identifiers {
// Exact match on all identifier fields
if strings.EqualFold(qID.Name, iID.Name) &&
strings.EqualFold(qID.Country, iID.Country) &&
Expand Down Expand Up @@ -141,11 +141,11 @@ func compareOrgExactIDs(w io.Writer, query *Organization, index *Organization, w
hasMatch := false

// Organization Registration/Tax IDs
if len(query.Identifier) > 0 && len(index.Identifier) > 0 {
if len(query.Identifiers) > 0 && len(index.Identifiers) > 0 {
fieldsCompared++
totalWeight += 15.0
for _, qID := range query.Identifier {
for _, iID := range index.Identifier {
for _, qID := range query.Identifiers {
for _, iID := range index.Identifiers {
// Exact match on all identifier fields
if strings.EqualFold(qID.Name, iID.Name) &&
strings.EqualFold(qID.Country, iID.Country) &&
Expand Down Expand Up @@ -461,8 +461,8 @@ func compareBusinessGovernmentIDs(query *Business, index *Business, weight float
return scorePiece{score: 0, weight: weight, fieldsCompared: 0, pieceType: "gov-ids-exact"}
}

qIDs := query.Identifier
iIDs := index.Identifier
qIDs := query.Identifiers
iIDs := index.Identifiers

if len(qIDs) == 0 || len(iIDs) == 0 {
return scorePiece{score: 0, weight: weight, fieldsCompared: 0, pieceType: "gov-ids-exact"}
Expand Down Expand Up @@ -501,8 +501,8 @@ func compareOrgGovernmentIDs(query *Organization, index *Organization, weight fl
return scorePiece{score: 0, weight: weight, fieldsCompared: 0, pieceType: "gov-ids-exact"}
}

qIDs := query.Identifier
iIDs := index.Identifier
qIDs := query.Identifiers
iIDs := index.Identifiers

if len(qIDs) == 0 || len(iIDs) == 0 {
return scorePiece{score: 0, weight: weight, fieldsCompared: 0, pieceType: "gov-ids-exact"}
Expand Down
6 changes: 3 additions & 3 deletions pkg/search/similarity_ofac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestSimilarity_OFAC_SDN_Business(t *testing.T) {
Business: &search.Business{
Name: "AUTONOMOUS NON-PROFIT ORGANIZATION DIALOG REGIONS",
Created: &businessCreatedAt,
Identifier: []search.Identifier{
Identifiers: []search.Identifier{
{
Name: "Business Registration Number",
Country: "Russia",
Expand All @@ -160,7 +160,7 @@ func TestSimilarity_OFAC_SDN_Business(t *testing.T) {
Type: search.EntityBusiness,
Business: &search.Business{
Name: "AUTO NON-PROFIT ORGANIZATION",
Identifier: []search.Identifier{
Identifiers: []search.Identifier{
{
Name: "Tax ID No.",
Country: "Russia",
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestSimilarity_OFAC_SDN_Business(t *testing.T) {
Type: search.EntityBusiness,
Business: &search.Business{
Name: "BETA Solutions",
Identifier: []search.Identifier{
Identifiers: []search.Identifier{
{Name: "Registration", Country: "US", Identifier: "99999"},
},
},
Expand Down

0 comments on commit dae7826

Please sign in to comment.