3
0

Make sys field matching more robust

This commit is contained in:
Tomaž Jerman 2020-07-14 12:18:53 +02:00
parent 305379aeb6
commit d19e305971
2 changed files with 18 additions and 17 deletions

View File

@ -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
}

View File

@ -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