@@ -238,11 +238,18 @@ func (client *DataRecordClient) ApplyDataRecord(ctx context.Context, recordId st
238
238
if nestedMap , ok := value .(map [string ]interface {}); ok {
239
239
delete (columns , key )
240
240
if len (nestedMap ) > 0 {
241
- tableLogicalName := nestedMap ["table_logical_name" ].(string )
241
+ tableLogicalName , ok := nestedMap ["table_logical_name" ].(string )
242
+ if ! ok {
243
+ return nil , fmt .Errorf ("table_logical_name field is missing or not a string" )
244
+ }
245
+ dataRecordId , ok := nestedMap ["data_record_id" ].(string )
246
+ if ! ok {
247
+ return nil , fmt .Errorf ("data_record_id field is missing or not a string" )
248
+ }
242
249
243
250
entityDefinition := getEntityDefinition (ctx , client , environmentUrl , tableLogicalName )
244
251
245
- columns [
fmt .
Sprintf (
"%[email protected] " ,
key )]
= fmt .
Sprintf (
"%s/api/data/%s/%s(%s)" ,
environmentUrl ,
constants .
DATAVERSE_API_VERSION ,
entityDefinition .
LogicalCollectionName ,
nestedMap [ "data_record_id" ] )
252
+ columns [
fmt .
Sprintf (
"%[email protected] " ,
key )]
= fmt .
Sprintf (
"%s/api/data/%s/%s(%s)" ,
environmentUrl ,
constants .
DATAVERSE_API_VERSION ,
entityDefinition .
LogicalCollectionName ,
dataRecordId )
246
253
}
247
254
}
248
255
if nestedMapList , ok := value .([]interface {}); ok {
@@ -317,8 +324,18 @@ func (client *DataRecordClient) ApplyDataRecord(ctx context.Context, recordId st
317
324
delete := true
318
325
for _ , nestedItem := range nestedMapList {
319
326
nestedMap := nestedItem .(map [string ]interface {})
320
- relationEntityDefinition := getEntityDefinition (ctx , client , environmentUrl , nestedMap ["table_logical_name" ].(string ))
321
- if existingRelation .OdataID == fmt .Sprintf ("%s/api/data/%s/%s(%s)" , environmentUrl , constants .DATAVERSE_API_VERSION , relationEntityDefinition .LogicalCollectionName , nestedMap ["data_record_id" ]) {
327
+
328
+ tableLogicalName , ok := nestedMap ["table_logical_name" ].(string )
329
+ if ! ok {
330
+ return nil , fmt .Errorf ("table_logical_name field is missing or not a string" )
331
+ }
332
+ dataRecordId , ok := nestedMap ["data_record_id" ].(string )
333
+ if ! ok {
334
+ return nil , fmt .Errorf ("data_record_id field is missing or not a string" )
335
+ }
336
+
337
+ relationEntityDefinition := getEntityDefinition (ctx , client , environmentUrl , tableLogicalName )
338
+ if existingRelation .OdataID == fmt .Sprintf ("%s/api/data/%s/%s(%s)" , environmentUrl , constants .DATAVERSE_API_VERSION , relationEntityDefinition .LogicalCollectionName , dataRecordId ) {
322
339
delete = false
323
340
break
324
341
}
@@ -338,12 +355,19 @@ func (client *DataRecordClient) ApplyDataRecord(ctx context.Context, recordId st
338
355
for _ , nestedItem := range nestedMapList {
339
356
nestedMap := nestedItem .(map [string ]interface {})
340
357
341
- tableLogicalName := nestedMap ["table_logical_name" ].(string )
358
+ tableLogicalName , ok := nestedMap ["table_logical_name" ].(string )
359
+ if ! ok {
360
+ return nil , fmt .Errorf ("table_logical_name field is missing or not a string" )
361
+ }
362
+ dataRecordId , ok := nestedMap ["data_record_id" ].(string )
363
+ if ! ok {
364
+ return nil , fmt .Errorf ("data_record_id field is missing or not a string" )
365
+ }
342
366
343
367
entityDefinition := getEntityDefinition (ctx , client , environmentUrl , tableLogicalName )
344
368
345
369
relation := RelationApiBody {
346
- OdataID : fmt .Sprintf ("%s/api/data/%s/%s(%s)" , environmentUrl , constants .DATAVERSE_API_VERSION , entityDefinition .LogicalCollectionName , nestedMap [ "data_record_id" ] ),
370
+ OdataID : fmt .Sprintf ("%s/api/data/%s/%s(%s)" , environmentUrl , constants .DATAVERSE_API_VERSION , entityDefinition .LogicalCollectionName , dataRecordId ),
347
371
}
348
372
_ , err = client .Api .Execute (ctx , "POST" , apiUrl .String (), nil , relation , []int {http .StatusOK , http .StatusNoContent }, nil )
349
373
if err != nil {
@@ -381,10 +405,15 @@ func (client *DataRecordClient) DeleteDataRecord(ctx context.Context, recordId s
381
405
for _ , nestedItem := range nestedMapList {
382
406
nestedMap := nestedItem .(map [string ]interface {})
383
407
408
+ dataRecordId , ok := nestedMap ["data_record_id" ].(string )
409
+ if ! ok {
410
+ return fmt .Errorf ("data_record_id field is missing or not a string" )
411
+ }
412
+
384
413
apiUrl = & url.URL {
385
414
Scheme : e .Scheme ,
386
415
Host : e .Host ,
387
- Path : fmt .Sprintf ("/api/data/%s/%s(%s)/%s(%s)/$ref" , constants .DATAVERSE_API_VERSION , tableEntityDefinition .LogicalCollectionName , recordId , key , nestedMap [ "data_record_id" ].( string ) ),
416
+ Path : fmt .Sprintf ("/api/data/%s/%s(%s)/%s(%s)/$ref" , constants .DATAVERSE_API_VERSION , tableEntityDefinition .LogicalCollectionName , recordId , key , dataRecordId ),
388
417
}
389
418
_ , err = client .Api .Execute (ctx , "DELETE" , apiUrl .String (), nil , nil , []int {http .StatusOK , http .StatusNoContent }, nil )
390
419
if err != nil {
0 commit comments