@@ -48,29 +48,55 @@ func (g *gleif) leiToOrgEntity(e *et.Event, ident *dbt.Entity) *dbt.Entity {
48
48
func (g * gleif ) updateOrgFromLEIRecord (e * et.Event , orgent * dbt.Entity , lei * leiRecord ) {
49
49
o := orgent .Asset .(* org.Organization )
50
50
51
+ if _ , err := g .createLEIFromRecord (e , orgent , lei ); err != nil {
52
+ msg := fmt .Sprintf ("failed to create the LEI Identifier from the record: %s" , err .Error ())
53
+ e .Session .Log ().Error (msg , slog .Group ("plugin" , "name" , g .name , "handler" , g .name ))
54
+ }
55
+
51
56
o .LegalName = lei .Attributes .Entity .LegalName .Name
57
+ if o .LegalName != "" {
58
+ _ = g .addIdentifiersToOrg (e , orgent , general .LegalName , []string {o .LegalName })
59
+ }
60
+
52
61
o .FoundingDate = lei .Attributes .Entity .CreationDate
62
+ o .Jurisdiction = lei .Attributes .Entity .Jurisdiction
63
+ o .RegistrationID = lei .Attributes .Entity .RegisteredAs
53
64
if lei .Attributes .Entity .Status == "ACTIVE" {
54
65
o .Active = true
55
66
} else {
56
67
o .Active = false
57
68
}
58
69
59
- street := strings .Join (lei .Attributes .Entity .HeadquartersAddress .AddressLines , " " )
60
- city := lei .Attributes .Entity .HeadquartersAddress .City
61
- province := lei .Attributes .Entity .HeadquartersAddress .Region
62
- if parts := strings .Split (province , "-" ); len (parts ) > 1 {
63
- province = parts [1 ]
70
+ addr := g .buildAddrFromLEIAddress (& lei .Attributes .Entity .LegalAddress )
71
+ _ = g .addAddress (e , orgent , general.SimpleRelation {Name : "legal_address" }, addr )
72
+
73
+ addr = g .buildAddrFromLEIAddress (& lei .Attributes .Entity .HeadquartersAddress )
74
+ _ = g .addAddress (e , orgent , general.SimpleRelation {Name : "hq_address" }, addr )
75
+
76
+ for _ , a := range lei .Attributes .Entity .OtherAddresses {
77
+ addr = g .buildAddrFromLEIAddress (& a )
78
+ _ = g .addAddress (e , orgent , general.SimpleRelation {Name : "location" }, addr )
64
79
}
65
- postalCode := lei .Attributes .Entity .HeadquartersAddress .PostalCode
66
- country := lei .Attributes .Entity .HeadquartersAddress .Country
67
80
68
- addr := fmt .Sprintf ("%s %s %s %s %s" , street , city , province , postalCode , country )
69
- _ = g .addAddress (e , orgent , general.SimpleRelation {Name : "location" }, addr )
81
+ _ = g .addIdentifiersToOrg (e , orgent , general .BankIDCode , lei .Attributes .BIC )
82
+ _ = g .addIdentifiersToOrg (e , orgent , general .MarketIDCode , lei .Attributes .MIC )
83
+ _ = g .addIdentifiersToOrg (e , orgent , general .GlobalOCID , []string {lei .Attributes .OCID })
84
+ _ = g .addIdentifiersToOrg (e , orgent , general .SPGlobalCompanyID , lei .Attributes .SPGlobal )
70
85
71
86
_ , _ = e .Session .Cache ().CreateEntity (orgent )
72
87
}
73
88
89
+ func (g * gleif ) buildAddrFromLEIAddress (addr * leiAddress ) string {
90
+ street := strings .Join (addr .AddressLines , " " )
91
+
92
+ province := addr .Region
93
+ if parts := strings .Split (province , "-" ); len (parts ) > 1 {
94
+ province = parts [1 ]
95
+ }
96
+
97
+ return fmt .Sprintf ("%s %s %s %s %s" , street , addr .City , province , addr .PostalCode , addr .Country )
98
+ }
99
+
74
100
func (g * gleif ) addAddress (e * et.Event , orgent * dbt.Entity , rel oam.Relation , addr string ) error {
75
101
loc := support .StreetAddressToLocation (addr )
76
102
if loc == nil {
@@ -88,20 +114,40 @@ func (g *gleif) addAddress(e *et.Event, orgent *dbt.Entity, rel oam.Relation, ad
88
114
Confidence : g .source .Confidence ,
89
115
})
90
116
91
- edge , err := e .Session .Cache ().CreateEdge (& dbt.Edge {
92
- Relation : rel ,
93
- FromEntity : orgent ,
94
- ToEntity : a ,
95
- })
96
- if err != nil && edge == nil {
117
+ if err := g .createRelation (e .Session , orgent , rel , a ); err != nil {
97
118
e .Session .Log ().Error (err .Error (), slog .Group ("plugin" , "name" , g .name , "handler" , g .name ))
98
119
return err
99
120
}
100
121
101
- _ , _ = e .Session .Cache ().CreateEdgeProperty (edge , & general.SourceProperty {
102
- Source : g .source .Name ,
103
- Confidence : g .source .Confidence ,
104
- })
122
+ return nil
123
+ }
124
+
125
+ func (g * gleif ) addIdentifiersToOrg (e * et.Event , orgent * dbt.Entity , idtype string , ids []string ) error {
126
+ for _ , id := range ids {
127
+ if id == "" {
128
+ continue
129
+ }
130
+
131
+ oamid := & general.Identifier {
132
+ UniqueID : fmt .Sprintf ("%s:%s" , idtype , id ),
133
+ EntityID : id ,
134
+ Type : idtype ,
135
+ }
136
+
137
+ ident , err := e .Session .Cache ().CreateAsset (oamid )
138
+ if err != nil || ident == nil {
139
+ return err
140
+ }
141
+
142
+ _ , _ = e .Session .Cache ().CreateEntityProperty (ident , & general.SourceProperty {
143
+ Source : g .source .Name ,
144
+ Confidence : g .source .Confidence ,
145
+ })
146
+
147
+ if err := g .createRelation (e .Session , orgent , general.SimpleRelation {Name : "id" }, ident ); err != nil {
148
+ return err
149
+ }
150
+ }
105
151
106
152
return nil
107
153
}
0 commit comments