Skip to content

Commit

Permalink
ofac: work out mapper for SDN -> Entity[SDN]
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Jan 8, 2024
1 parent 53f9561 commit a5dcd7c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/ofac/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ofac

import (
"strings"
"time"

"github.com/moov-io/watchman/pkg/search"
)
Expand All @@ -22,6 +23,8 @@ func ToEntity(sdn SDN) search.Entity[SDN] {
SourceData: sdn,
}

remarks := splitRemarks(sdn.Remarks)

switch strings.ToLower(strings.TrimSpace(sdn.SDNType)) {
case "-0-", "":
out.Type = search.EntityBusiness // TODO(adam): or EntityOrganization
Expand All @@ -32,9 +35,12 @@ func ToEntity(sdn SDN) search.Entity[SDN] {
out.Person = &search.Person{
Name: sdn.SDNName,
}
out.Person.BirthDate = withFirstP(findRemarkValues(remarks, "DOB"), func(in string) *time.Time {
t, _ := time.Parse("02 Jan 2006", in)
return &t
})

// TODO(adam):
// DOB 02 Aug 1991;
// nationality Russia;
// Gender Male;
// Passport 0291622 (Belize);
Expand Down
43 changes: 43 additions & 0 deletions pkg/ofac/mapper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ofac

import (
"path/filepath"
"testing"
"time"

"github.com/moov-io/watchman/pkg/search"

"github.com/stretchr/testify/require"
)

func TestMapper(t *testing.T) {
res, err := Read(filepath.Join("..", "..", "test", "testdata", "sdn.csv"))
require.NoError(t, err)

var sdn *SDN
for i := range res.SDNs {
if res.SDNs[i].EntityID == "15102" {
sdn = res.SDNs[i]
}
}
require.NotNil(t, sdn)

e := ToEntity(*sdn)
require.Equal(t, "MORENO, Daniel", e.Name)
require.Equal(t, search.EntityPerson, e.Type)
require.Equal(t, search.SourceUSOFAC, e.Source)

require.NotNil(t, e.Person)
require.Equal(t, "MORENO, Daniel", e.Person.Name)
require.Equal(t, "", string(e.Person.Gender))
require.Equal(t, "1972-10-12T00:00:00Z", e.Person.BirthDate.Format(time.RFC3339))
require.Nil(t, e.Person.DeathDate)
require.Len(t, e.Person.GovernmentIDs, 0)

require.Nil(t, e.Business)
require.Nil(t, e.Organization)
require.Nil(t, e.Aircraft)
require.Nil(t, e.Vessel)

require.Equal(t, "15102", e.SourceData.EntityID)
}
23 changes: 23 additions & 0 deletions pkg/ofac/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,29 @@ func findRemarkValues(remarks []string, suffix string) []string {
return out
}

func withFirst(values []string) string {

Check failure on line 291 in pkg/ofac/reader.go

View workflow job for this annotation

GitHub Actions / Go Build (ubuntu-latest, 5, 0)

func `withFirst` is unused (unused)
if len(values) == 0 {
return ""
}
return values[0]
}

func withFirstF[T any](values []string, f func(string) T) T {

Check failure on line 298 in pkg/ofac/reader.go

View workflow job for this annotation

GitHub Actions / Go Build (ubuntu-latest, 5, 0)

func `withFirstF` is unused (unused)
if len(values) == 0 {
var zero T
return zero
}
return f(values[0])
}

func withFirstP[T any](values []string, f func(string) *T) *T {
if len(values) == 0 {
var zero T
return &zero
}
return f(values[0])
}

var (
digitalCurrencies = []string{
"XBT", // Bitcoin
Expand Down

0 comments on commit a5dcd7c

Please sign in to comment.