@@ -33,53 +33,60 @@ function(action, entity, config){
33
33
update_files <- action $ getOption(" update_files" )
34
34
communities <- action $ getOption(" communities" )
35
35
36
- # zenodo object
37
- zenodo_metadata <- NULL
38
-
39
- # how to deal with existing records / new versions
40
- # we try first to use DOI if existing, assuming it's a concept DOI, if not a simple DOI
41
- # if nothing is found, we use the default get depositions by identifier, used if no DOI is specified
42
- # this approach is possible because the Zenodo record has a related identifier as URN, specified when
43
- # creating the record. For existing record we also check the presence of the URN as related identifier
44
- # e.g. my-metadata-identifier
45
- deposits <- NULL
46
- if (! is.null(entity $ identifiers [[" doi" ]])){
47
- # TODO review if getting deposit with concept DOI we don't inherit bucket link for doing file upload with new API
48
- deposit <- try(ZENODO $ getDepositionByConceptDOI(entity $ identifiers [[" doi" ]]), silent = TRUE ) # try to get latest record with concept DOI
49
- if (is(deposit , " try-error" )) deposit = NULL
50
- if (is.null(deposit )) deposit <- ZENODO $ getDepositionByDOI(entity $ identifiers [[" doi" ]]) # try to get record with specific DOI
51
- if (! is.null(deposit )) deposits <- list (deposit )
52
- }
53
-
54
- if (is.null(deposits )){
55
- deposit <- NULL
56
- if (! is.null(entity $ identifiers [[" zenodo_doi_to_save" ]])){
57
- deposit <- ZENODO $ getDepositionByDOI(entity $ identifiers [[" zenodo_doi_to_save" ]]) # try to get record with specific DOI
36
+ # get_zenodo_metadata
37
+ get_zenodo_metadata = function (){
38
+ # zenodo object
39
+ zen_meta <- NULL
40
+
41
+ # how to deal with existing records / new versions
42
+ # we try first to use DOI if existing, assuming it's a concept DOI, if not a simple DOI
43
+ # if nothing is found, we use the default get depositions by identifier, used if no DOI is specified
44
+ # this approach is possible because the Zenodo record has a related identifier as 'other', specified when
45
+ # creating the record. For existing record we also check the presence of the 'other' as related identifier
46
+ # e.g. my-metadata-identifier
47
+ deposits <- NULL
48
+ if (! is.null(entity $ identifiers [[" doi" ]])){
49
+ # TODO review if getting deposit with concept DOI we don't inherit bucket link for doing file upload with new API
50
+ deposit <- try(ZENODO $ getDepositionByConceptDOI(entity $ identifiers [[" doi" ]]), silent = TRUE ) # try to get latest record with concept DOI
51
+ if (is(deposit , " try-error" )) deposit = NULL
52
+ if (is.null(deposit )) deposit <- ZENODO $ getDepositionByDOI(entity $ identifiers [[" doi" ]]) # try to get record with specific DOI
53
+ if (! is.null(deposit )) deposits <- list (deposit )
58
54
}
59
- if (! is.null(deposit )) deposits <- list (deposit )
60
- }
61
-
62
- if (is.null(deposits )){
63
- deposits <- ZENODO $ getDepositions(q = entity $ identifiers [[" id" ]], size = 1000L )
64
- }
65
- # check related identifier
66
- if (length(deposits )> 0 ){
67
- invisible (lapply(deposits , function (deposit ){
68
- related_identifiers <- deposit $ metadata $ related_identifiers
69
- if (! is.null(related_identifiers )){
70
- for (related_identifier in related_identifiers ){
71
- if (related_identifier $ scheme == " urn" ){
72
- if (related_identifier $ identifier == entity $ identifiers [[" id" ]] &
73
- related_identifier $ relation_type $ id == " isidenticalto" ){
74
- zenodo_metadata <<- deposit
75
- break
55
+
56
+ if (is.null(deposits )){
57
+ deposit <- NULL
58
+ if (! is.null(entity $ identifiers [[" zenodo_doi_to_save" ]])){
59
+ deposit <- ZENODO $ getDepositionByDOI(entity $ identifiers [[" zenodo_doi_to_save" ]]) # try to get record with specific DOI
60
+ }
61
+ if (! is.null(deposit )) deposits <- list (deposit )
62
+ }
63
+
64
+ if (is.null(deposits )){
65
+ deposits <- ZENODO $ getDepositions(q = entity $ identifiers [[" id" ]], size = 1000L )
66
+ }
67
+ # check related identifier
68
+ if (length(deposits )> 0 ){
69
+ invisible (lapply(deposits , function (deposit ){
70
+ related_identifiers <- deposit $ metadata $ related_identifiers
71
+ if (! is.null(related_identifiers )){
72
+ for (related_identifier in related_identifiers ){
73
+ if (related_identifier $ scheme == " other" ){
74
+ if (related_identifier $ identifier == entity $ identifiers [[" id" ]] &
75
+ related_identifier $ relation_type $ id == " isidenticalto" ){
76
+ zen_meta <<- deposit
77
+ break
78
+ }
76
79
}
77
80
}
78
81
}
79
- }
80
- }))
82
+ }))
83
+ }
84
+ return (zen_meta )
81
85
}
82
86
87
+ # zenodo_metadata
88
+ zenodo_metadata = get_zenodo_metadata()
89
+
83
90
# doi
84
91
doi <- NULL
85
92
@@ -99,12 +106,12 @@ function(action, entity, config){
99
106
}
100
107
zenodo_metadata $ addRelatedIdentifier(
101
108
identifier = entity $ identifiers [[" id" ]],
102
- scheme = " urn " ,
109
+ scheme = " other " ,
103
110
relation_type = " isidenticalto"
104
111
)
105
112
record_status <- zenodo_metadata $ status
106
113
}else {
107
- config $ logger.info(sprintf(" Zenodo: Existing record with related identifier '%s' (URN scheme)" , entity $ identifiers [[" id" ]]))
114
+ config $ logger.info(sprintf(" Zenodo: Existing record with related identifier '%s' ('other' scheme)" , entity $ identifiers [[" id" ]]))
108
115
update <- TRUE
109
116
record_status <- zenodo_metadata $ status
110
117
@@ -120,6 +127,24 @@ function(action, entity, config){
120
127
}
121
128
}
122
129
130
+ if (length(zenodo_metadata $ getVersions())> 0 && strategy == " newversion" ){
131
+ # to know if the record has been already published, we check if there is at least one version set
132
+ # the property "is_published" is transient to the record and can't be used
133
+ if (! depositWithFiles ){
134
+ # the first run of the action will be skipped and we will wait for the final generic_uploader run
135
+ # with depositWithFiles=TRUE to run the version to avoid two versions to be created
136
+ config $ logger.info(sprintf(" Zenodo: record '%s' already published. Skip 1st run to create version with generic uploader at the end of the workflow" , zenodo_metadata $ id ))
137
+ return (TRUE )
138
+ }
139
+ }
140
+
141
+ if (record_status == " new_version_draft" ){
142
+ config $ logger.info(" Draft version already set. Discard initial changes before publishing new version..." )
143
+ ZENODO $ discardChanges(zenodo_metadata $ id )
144
+ zenodo_metadata = get_zenodo_metadata()
145
+ record_status = zenodo_metadata $ status
146
+ }
147
+
123
148
# case where bucket is not kept by zenodo we try to get it from added resource
124
149
if (! " bucket" %in% names(zenodo_metadata $ links )) if (! is.null(entity $ resources $ zenodo_bucket )){
125
150
zenodo_metadata $ links $ bucket <- entity $ resources $ zenodo_bucket
@@ -393,38 +418,80 @@ function(action, entity, config){
393
418
}
394
419
}
395
420
}
396
- config $ logger.info(sprintf( " Deposit record with id '%s' - publish = %s " , zenodo_metadata $ id , tolower(as.character( publish ))) )
421
+ print( record_status )
397
422
out <- switch (record_status ,
398
- " draft" = ZENODO $ depositRecord(zenodo_metadata , publish = publish ),
423
+ " draft" = {
424
+ config $ logger.info(sprintf(" Deposit draft record with id '%s' - publish = %s" , zenodo_metadata $ id , tolower(as.character(publish ))))
425
+ ZENODO $ depositRecord(zenodo_metadata , publish = publish )
426
+ },
399
427
" published" = {
400
428
switch (strategy ,
401
- " edition" = ZENODO $ depositRecord(zenodo_metadata , publish = publish ),
402
- " newversion" = {
403
- data_files <- list.files(file.path(getwd()," data" ), pattern = depositDataPattern , full.names = T )
404
-
405
- if (zipEachDataFile ){
406
- config $ logger.info(" Zenodo: 'zipEachDaTafile' is true - zipping data files" )
407
- data_files <- lapply(data_files , function (data_file ){
408
- data_file = basename(data_file )
409
- config $ logger.info(sprintf(" Zenodo: 'zipEachDaTafile' is true - zipping each data file '%s'" , data_file ))
410
- fileparts <- unlist(strsplit(data_file , " \\ ." ))
411
- if (length(fileparts )> 1 ) fileparts <- fileparts [1 : (length(fileparts )- 1 )]
412
- filename <- paste0(fileparts , collapse = " ." )
413
- outfilename <- file.path(getwd(), " data" , paste0(filename , " .zip" ))
414
- zip :: zipr(zipfile = outfilename , files = data_file )
415
- return (outfilename )
416
- })
417
- }
418
-
419
- metadata_files <- list.files(file.path(getwd()," metadata" ), full.names = TRUE )
420
- files_to_upload <- if (depositWithFiles & (! update | (update & update_files ))) c(data_files , metadata_files ) else NULL
421
- ZENODO $ depositRecordVersion(
422
- record = zenodo_metadata ,
423
- delete_latest_files = deleteOldFiles ,
424
- files = files_to_upload ,
425
- publish = publish
426
- )
427
- }
429
+ " edition" = {
430
+ config $ logger.info(sprintf(" Edit published record with id '%s' - publish = %s" , zenodo_metadata $ id , tolower(as.character(publish ))))
431
+ ZENODO $ depositRecord(zenodo_metadata , publish = publish )
432
+ },
433
+ " newversion" = {
434
+ config $ logger.info(sprintf(" Deposit record version with id '%s' - publish = %s" , zenodo_metadata $ id , tolower(as.character(publish ))))
435
+ data_files <- list.files(file.path(getwd()," data" ), pattern = depositDataPattern , full.names = T )
436
+
437
+ if (zipEachDataFile ){
438
+ config $ logger.info(" Zenodo: 'zipEachDaTafile' is true - zipping data files" )
439
+ data_files <- lapply(data_files , function (data_file ){
440
+ data_file = basename(data_file )
441
+ config $ logger.info(sprintf(" Zenodo: 'zipEachDaTafile' is true - zipping each data file '%s'" , data_file ))
442
+ fileparts <- unlist(strsplit(data_file , " \\ ." ))
443
+ if (length(fileparts )> 1 ) fileparts <- fileparts [1 : (length(fileparts )- 1 )]
444
+ filename <- paste0(fileparts , collapse = " ." )
445
+ outfilename <- file.path(getwd(), " data" , paste0(filename , " .zip" ))
446
+ zip :: zipr(zipfile = outfilename , files = data_file )
447
+ return (outfilename )
448
+ })
449
+ }
450
+
451
+ metadata_files <- list.files(file.path(getwd()," metadata" ), full.names = TRUE )
452
+ files_to_upload <- if (depositWithFiles & (! update | (update & update_files ))) c(data_files , metadata_files ) else NULL
453
+
454
+ config $ logger.info(" Deposit record version..." )
455
+ ZENODO $ depositRecordVersion(
456
+ record = zenodo_metadata ,
457
+ delete_latest_files = deleteOldFiles ,
458
+ files = files_to_upload ,
459
+ publish = publish
460
+ )
461
+ }
462
+ )
463
+ },
464
+ " new_version_draft" = {
465
+ switch (strategy ,
466
+ " newversion" = {
467
+ config $ logger.info(sprintf(" Deposit record version with id '%s' - publish = %s" , zenodo_metadata $ id , tolower(as.character(publish ))))
468
+ data_files <- list.files(file.path(getwd()," data" ), pattern = depositDataPattern , full.names = T )
469
+
470
+ if (zipEachDataFile ){
471
+ config $ logger.info(" Zenodo: 'zipEachDaTafile' is true - zipping data files" )
472
+ data_files <- lapply(data_files , function (data_file ){
473
+ data_file = basename(data_file )
474
+ config $ logger.info(sprintf(" Zenodo: 'zipEachDaTafile' is true - zipping each data file '%s'" , data_file ))
475
+ fileparts <- unlist(strsplit(data_file , " \\ ." ))
476
+ if (length(fileparts )> 1 ) fileparts <- fileparts [1 : (length(fileparts )- 1 )]
477
+ filename <- paste0(fileparts , collapse = " ." )
478
+ outfilename <- file.path(getwd(), " data" , paste0(filename , " .zip" ))
479
+ zip :: zipr(zipfile = outfilename , files = data_file )
480
+ return (outfilename )
481
+ })
482
+ }
483
+
484
+ metadata_files <- list.files(file.path(getwd()," metadata" ), full.names = TRUE )
485
+ files_to_upload <- if (depositWithFiles & (! update | (update & update_files ))) c(data_files , metadata_files ) else NULL
486
+
487
+ config $ logger.info(" Deposit record version..." )
488
+ ZENODO $ depositRecordVersion(
489
+ record = zenodo_metadata ,
490
+ delete_latest_files = deleteOldFiles ,
491
+ files = files_to_upload ,
492
+ publish = publish
493
+ )
494
+ }
428
495
)
429
496
}
430
497
)
0 commit comments