@@ -241,7 +241,10 @@ func CreateOrgAsset(session et.Session, obj *dbt.Entity, rel oam.Relation, o *or
241
241
if o == nil || o .Name == "" {
242
242
return nil , errors .New ("missing the organization name" )
243
243
}
244
- if obj != nil && rel != nil && src != nil {
244
+ if src == nil {
245
+ return nil , errors .New ("missing the source" )
246
+ }
247
+ if obj != nil && rel != nil {
245
248
if orgent := orgDedupChecks (session , obj , o ); orgent != nil {
246
249
if err := createRelation (session , obj , rel , orgent , src ); err != nil {
247
250
return nil , err
@@ -283,32 +286,37 @@ func CreateOrgAsset(session et.Session, obj *dbt.Entity, rel oam.Relation, o *or
283
286
}
284
287
285
288
func orgDedupChecks (session et.Session , obj * dbt.Entity , o * org.Organization ) * dbt.Entity {
286
- var result * dbt.Entity
287
-
288
289
switch obj .Asset .(type ) {
289
290
case * contact.ContactRecord :
290
- if org , found := orgNameExistsInContactRecord (session , obj , o .Name ); found {
291
- result = org
291
+ for _ , name := range []string {o .Name , o .LegalName } {
292
+ if name != "" {
293
+ if org , found := orgNameExistsInContactRecord (session , obj , name ); found {
294
+ return org
295
+ }
296
+ }
292
297
}
293
298
if org , err := orgExistsAndSharesLocEntity (session , obj , o ); err == nil {
294
- result = org
299
+ return org
295
300
}
296
301
if org , err := orgExistsAndSharesAncestorEntity (session , obj , o ); err == nil {
297
- result = org
302
+ return org
298
303
}
299
304
case * org.Organization :
300
- if org , found := orgNameRelatedToOrganization (session , obj , o .Name ); found {
301
- result = org
305
+ for _ , name := range []string {o .Name , o .LegalName } {
306
+ if name != "" {
307
+ if org , found := orgNameRelatedToOrganization (session , obj , name ); found {
308
+ return org
309
+ }
310
+ }
302
311
}
303
312
if org , err := orgExistsAndSharesLocEntity (session , obj , o ); err == nil {
304
- result = org
313
+ return org
305
314
}
306
315
if org , err := orgExistsAndSharesAncestorEntity (session , obj , o ); err == nil {
307
- result = org
316
+ return org
308
317
}
309
318
}
310
-
311
- return result
319
+ return nil
312
320
}
313
321
314
322
func orgHasName (session et.Session , org * dbt.Entity , name string ) bool {
0 commit comments