@@ -241,7 +241,10 @@ func CreateOrgAsset(session et.Session, obj *dbt.Entity, rel oam.Relation, o *or
241241 if o == nil || o .Name == "" {
242242 return nil , errors .New ("missing the organization name" )
243243 }
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 {
245248 if orgent := orgDedupChecks (session , obj , o ); orgent != nil {
246249 if err := createRelation (session , obj , rel , orgent , src ); err != nil {
247250 return nil , err
@@ -283,32 +286,37 @@ func CreateOrgAsset(session et.Session, obj *dbt.Entity, rel oam.Relation, o *or
283286}
284287
285288func orgDedupChecks (session et.Session , obj * dbt.Entity , o * org.Organization ) * dbt.Entity {
286- var result * dbt.Entity
287-
288289 switch obj .Asset .(type ) {
289290 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+ }
292297 }
293298 if org , err := orgExistsAndSharesLocEntity (session , obj , o ); err == nil {
294- result = org
299+ return org
295300 }
296301 if org , err := orgExistsAndSharesAncestorEntity (session , obj , o ); err == nil {
297- result = org
302+ return org
298303 }
299304 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+ }
302311 }
303312 if org , err := orgExistsAndSharesLocEntity (session , obj , o ); err == nil {
304- result = org
313+ return org
305314 }
306315 if org , err := orgExistsAndSharesAncestorEntity (session , obj , o ); err == nil {
307- result = org
316+ return org
308317 }
309318 }
310-
311- return result
319+ return nil
312320}
313321
314322func orgHasName (session et.Session , org * dbt.Entity , name string ) bool {
0 commit comments