diff --git a/pkg/ofac/mapper.go b/pkg/ofac/mapper.go index 7c084c9b..69384d53 100644 --- a/pkg/ofac/mapper.go +++ b/pkg/ofac/mapper.go @@ -2,6 +2,7 @@ package ofac import ( "strings" + "time" "github.com/moov-io/watchman/pkg/search" ) @@ -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 @@ -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); diff --git a/pkg/ofac/mapper_test.go b/pkg/ofac/mapper_test.go new file mode 100644 index 00000000..c1cbf054 --- /dev/null +++ b/pkg/ofac/mapper_test.go @@ -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) +} diff --git a/pkg/ofac/reader.go b/pkg/ofac/reader.go index 1503c2da..9037cdb4 100644 --- a/pkg/ofac/reader.go +++ b/pkg/ofac/reader.go @@ -288,6 +288,29 @@ func findRemarkValues(remarks []string, suffix string) []string { return out } +func withFirst(values []string) string { + if len(values) == 0 { + return "" + } + return values[0] +} + +func withFirstF[T any](values []string, f func(string) T) T { + 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