@@ -48,29 +48,55 @@ func (g *gleif) leiToOrgEntity(e *et.Event, ident *dbt.Entity) *dbt.Entity {
4848func (g * gleif ) updateOrgFromLEIRecord (e * et.Event , orgent * dbt.Entity , lei * leiRecord ) {
4949 o := orgent .Asset .(* org.Organization )
5050
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+
5156 o .LegalName = lei .Attributes .Entity .LegalName .Name
57+ if o .LegalName != "" {
58+ _ = g .addIdentifiersToOrg (e , orgent , general .LegalName , []string {o .LegalName })
59+ }
60+
5261 o .FoundingDate = lei .Attributes .Entity .CreationDate
62+ o .Jurisdiction = lei .Attributes .Entity .Jurisdiction
63+ o .RegistrationID = lei .Attributes .Entity .RegisteredAs
5364 if lei .Attributes .Entity .Status == "ACTIVE" {
5465 o .Active = true
5566 } else {
5667 o .Active = false
5768 }
5869
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 )
6479 }
65- postalCode := lei .Attributes .Entity .HeadquartersAddress .PostalCode
66- country := lei .Attributes .Entity .HeadquartersAddress .Country
6780
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 )
7085
7186 _ , _ = e .Session .Cache ().CreateEntity (orgent )
7287}
7388
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+
74100func (g * gleif ) addAddress (e * et.Event , orgent * dbt.Entity , rel oam.Relation , addr string ) error {
75101 loc := support .StreetAddressToLocation (addr )
76102 if loc == nil {
@@ -88,20 +114,40 @@ func (g *gleif) addAddress(e *et.Event, orgent *dbt.Entity, rel oam.Relation, ad
88114 Confidence : g .source .Confidence ,
89115 })
90116
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 {
97118 e .Session .Log ().Error (err .Error (), slog .Group ("plugin" , "name" , g .name , "handler" , g .name ))
98119 return err
99120 }
100121
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+ }
105151
106152 return nil
107153}
0 commit comments