From d19e3059716aef8a622aef87be98dc5024840c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Tue, 14 Jul 2020 12:18:53 +0200 Subject: [PATCH] Make sys field matching more robust --- pkg/ngimporter/import_users.go | 19 ++++++++++--------- pkg/ngimporter/types/import_node.go | 16 ++++++++-------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pkg/ngimporter/import_users.go b/pkg/ngimporter/import_users.go index 3f9ac3e20..072373723 100644 --- a/pkg/ngimporter/import_users.go +++ b/pkg/ngimporter/import_users.go @@ -5,6 +5,7 @@ import ( "context" "encoding/csv" "io" + "strings" "time" "github.com/cortezaproject/corteza-server/compose/repository" @@ -54,28 +55,28 @@ func importUsers(ctx context.Context, is *types.ImportSource, ns *cct.Namespace) // when creating users we only care about a handfull of values. // the rest are included in the module - switch h { - case "Username": + switch strings.ToLower(h) { + case "username": u.Username = record[i] break - case "Email": + case "email": u.Email = record[i] break - case "FirstName": + case "firstname": u.Name = record[i] break - case "LastName": + case "lastname": u.Name = u.Name + " " + record[i] break - case "Alias": + case "alias": u.Handle = record[i] break - case "CreatedDate": + case "createddate": if val != "" { u.CreatedAt, err = time.Parse(types.SfDateTimeLayout, val) if err != nil { @@ -84,7 +85,7 @@ func importUsers(ctx context.Context, is *types.ImportSource, ns *cct.Namespace) } break - case "LastModifiedDate": + case "lastmodifieddate": if val != "" { tt, err := time.Parse(types.SfDateTimeLayout, val) u.UpdatedAt = &tt @@ -95,7 +96,7 @@ func importUsers(ctx context.Context, is *types.ImportSource, ns *cct.Namespace) break // ignore deleted values, as SF provides minimal info about those - case "IsDeleted": + case "isdeleted": if val == "1" { goto looper } diff --git a/pkg/ngimporter/types/import_node.go b/pkg/ngimporter/types/import_node.go index 5c96c215a..968fc1983 100644 --- a/pkg/ngimporter/types/import_node.go +++ b/pkg/ngimporter/types/import_node.go @@ -415,19 +415,19 @@ func (n *ImportNode) importNodeSource(users map[string]uint64, repo repository.R // system values should be kept on the record's root level if isSysField(h) { - switch h { - case "OwnerId": + switch strings.ToLower(h) { + case "ownerid": rr.OwnedBy = users[val] break // ignore deleted values, as SF provides minimal info about those - case "IsDeleted": - if val == "1" { + case "isdeleted": + if val == "1" || strings.ToLower(val) == "true" { goto looper } break - case "CreatedDate": + case "createddate": if val != "" { rr.CreatedAt, err = time.Parse(SfDateTimeLayout, val) if err != nil { @@ -436,15 +436,15 @@ func (n *ImportNode) importNodeSource(users map[string]uint64, repo repository.R } break - case "CreatedById": + case "createdbyid": rr.CreatedBy = users[val] break - case "LastModifiedById": + case "lastmodifiedbyid": rr.UpdatedBy = users[val] break - case "LastModifiedDate": + case "lastmodifieddate": if val != "" { tt, err := time.Parse(SfDateTimeLayout, val) rr.UpdatedAt = &tt