@@ -41,7 +41,7 @@ function(action, entity, config){
41
41
# if nothing is found, we use the default get depositions by identifier, used if no DOI is specified
42
42
# this approach is possible because the Zenodo record has a related identifier as URN, specified when
43
43
# creating the record. For existing record we also check the presence of the URN as related identifier
44
- # e.g. urn: my-metadata-identifier
44
+ # e.g. my-metadata-identifier
45
45
deposits <- NULL
46
46
if (! is.null(entity $ identifiers [[" doi" ]])){
47
47
# TODO review if getting deposit with concept DOI we don't inherit bucket link for doing file upload with new API
@@ -68,10 +68,9 @@ function(action, entity, config){
68
68
related_identifiers <- deposit $ metadata $ related_identifiers
69
69
if (! is.null(related_identifiers )){
70
70
for (related_identifier in related_identifiers ){
71
- if (startsWith(related_identifier $ identifier ," urn" )){
72
- related_id <- unlist(strsplit(related_identifier $ identifier , " urn:" ))[2 ]
73
- if (related_id == entity $ identifiers [[" id" ]] &
74
- related_identifier $ relation == " isIdenticalTo" ){
71
+ if (related_identifier $ scheme == " urn" ){
72
+ if (related_identifier $ identifier == entity $ identifiers [[" id" ]] &
73
+ related_identifier $ relation_type $ id == " isidenticalto" ){
75
74
zenodo_metadata <<- deposit
76
75
break
77
76
}
@@ -86,23 +85,34 @@ function(action, entity, config){
86
85
87
86
# action to perform: create empty record or update existing record
88
87
update <- FALSE
89
- record_state <- NULL
88
+ record_status <- NULL
90
89
if (is.null(zenodo_metadata )){
91
- config $ logger.info(sprintf(" Zenodo: No existing Zenodo record with related identifier '%s'" , paste0( " urn: " , entity $ identifiers [[" id" ]]) ))
90
+ config $ logger.info(sprintf(" Zenodo: No existing Zenodo record with related identifier '%s'" , entity $ identifiers [[" id" ]]))
92
91
config $ logger.info(" Zenodo: creating a new deposit empty record" )
93
- zenodo_metadata <- ZENODO $ createEmptyRecord()
92
+ reserveDOI = TRUE
93
+ if (! is.null(entity $ identifiers [[" doi" ]])) if (regexpr(" zenodo" , entity $ identifiers [[" doi" ]])< 0 ){
94
+ reserveDOI = FALSE
95
+ }
96
+ zenodo_metadata <- ZENODO $ createEmptyRecord(reserveDOI = reserveDOI )
94
97
if (" bucket" %in% names(zenodo_metadata $ links )){
95
98
entity $ addResource(" zenodo_bucket" , zenodo_metadata $ links $ bucket ) # attempt to keep bucket since zenodo seems not to retrieve always bucket link
96
99
}
97
- zenodo_metadata $ addRelatedIdentifier(" isIdenticalTo" , paste(" urn" , entity $ identifiers [[" id" ]], sep = " :" ))
98
- record_state <- zenodo_metadata $ state
100
+ zenodo_metadata $ addRelatedIdentifier(
101
+ identifier = entity $ identifiers [[" id" ]],
102
+ scheme = " urn" ,
103
+ relation_type = " isidenticalto"
104
+ )
105
+ record_status <- zenodo_metadata $ status
99
106
}else {
100
- config $ logger.info(sprintf(" Zenodo: Existing record with related identifier '%s'" , paste0( " urn: " , entity $ identifiers [[" id" ]]) ))
107
+ config $ logger.info(sprintf(" Zenodo: Existing record with related identifier '%s' (URN scheme) " , entity $ identifiers [[" id" ]]))
101
108
update <- TRUE
102
- record_state <- zenodo_metadata $ state
109
+ record_status <- zenodo_metadata $ status
103
110
104
- # case of submitted records and 'edition' strategy, need to unlock record
105
- if (zenodo_metadata $ state == " done" && strategy == " edition" ){
111
+ # case of published records and 'edition' strategy, need to unlock record
112
+ if (record_status == " published" &&
113
+ zenodo_metadata $ is_published &&
114
+ ! zenodo_metadata $ is_draft &&
115
+ strategy == " edition" ){
106
116
config $ logger.info(sprintf(" Zenodo: record '%s' already published. Need to unlock it for edition" , zenodo_metadata $ id ))
107
117
unlocked_rec <- ZENODO $ editRecord(zenodo_metadata $ id )
108
118
if (is(unlocked_rec , " ZenodoRecord" )){
@@ -116,7 +126,7 @@ function(action, entity, config){
116
126
}
117
127
}
118
128
119
- doi <- zenodo_metadata $ metadata $ prereserve_doi $ doi
129
+ doi <- zenodo_metadata $ pids $ doi $ identifier
120
130
121
131
# if entity already comes with a DOI, we set it (this might be a preset DOI from Zenodo or elsewhere)
122
132
if (! is.null(entity $ identifiers [[" doi" ]])){
@@ -138,20 +148,20 @@ function(action, entity, config){
138
148
}
139
149
# basic record description
140
150
zenodo_metadata $ setTitle(entity $ titles [[" title" ]])
151
+ if (! is.null(entity $ titles [[" alternative" ]])){
152
+ zenodo_metadata $ addAdditionalTitle(entity $ titles [[" alternative" ]], type = " alternative-title" )
153
+ }
141
154
zenodo_metadata $ setDescription(entity $ descriptions [[" abstract" ]])
142
- zenodo_metadata $ setNotes(entity $ descriptions [[" info" ]])
143
-
155
+ if (! is.null(entity $ descriptions [[" info" ]])){
156
+ zenodo_metadata $ addAdditionalDescription(entity $ descriptions [[" info" ]], type = " technical-info" )
157
+ }
158
+
144
159
# keywords (free text) & subjects
145
160
zenodo_metadata $ metadata $ keywords <- list ()
146
161
zenodo_metadata $ metadata $ subjects <- list ()
147
162
for (subject in entity $ subjects ){
148
163
for (kwd in subject $ keywords ){
149
- kwd_name <- kwd $ name
150
- kwd_uri <- kwd $ uri
151
- if (is.null(kwd_uri ))
152
- zenodo_metadata $ addKeyword(kwd_name )
153
- else
154
- zenodo_metadata $ addSubject(kwd_name , kwd_uri )
164
+ zenodo_metadata $ addSubject(kwd $ name )
155
165
}
156
166
}
157
167
@@ -164,20 +174,19 @@ function(action, entity, config){
164
174
if (! is.null(edition )){
165
175
zenodo_metadata $ setVersion(edition )
166
176
}
167
- # upload type
168
- # TODO think on how to map upload types between Dublin core, ISO/OGC metadata, Zenodo
169
- if (! is.null(entity $ types [[" generic" ]])) zenodo_metadata $ setUploadType (tolower(entity $ types [[" generic" ]]))
170
- if (! is.null(entity $ types [[" zenodoUploadType " ]])) zenodo_metadata $ setUploadType (entity $ types [[" zenodoUploadType " ]])
177
+ # resource type
178
+ # TODO think on how to map resource types between Dublin core, ISO/OGC metadata, Zenodo
179
+ if (! is.null(entity $ types [[" generic" ]])) zenodo_metadata $ setResourceType (tolower(entity $ types [[" generic" ]]))
180
+ if (! is.null(entity $ types [[" zenodoResourceType " ]])) zenodo_metadata $ setResourceType (entity $ types [[" zenodoResourceType " ]])
171
181
172
- # publication type
173
- if (zenodo_metadata $ metadata $ upload_type == " publication" ){
174
- if (! is.null(entity $ types [[" zenodoPublicationType" ]]))
175
- zenodo_metadata $ setPublicationType(entity $ types [[" zenodoPublicationType" ]])
176
- }
177
- # image type
178
- if (zenodo_metadata $ metadata $ upload_type == " image" ){
179
- if (! is.null(entity $ types [[" zenodoImageType" ]]))
180
- zenodo_metadata $ setImageType(entity $ types [[" zenodoImageType" ]])
182
+ # publisher
183
+ if (length(entity $ contacts )> 0 ){
184
+ publisher <- " Zenodo"
185
+ publishers <- entity $ contacts [sapply(entity $ contacts , function (x ){x $ role == " publisher" })]
186
+ if (length(publishers )> 0 ){
187
+ publisher = publishers [[1 ]]$ organizationName # we assume publisher is an organization
188
+ }
189
+ zenodo_metadata $ setPublisher(publisher )
181
190
}
182
191
183
192
# creators
@@ -204,14 +213,14 @@ function(action, entity, config){
204
213
if (is.na(contact $ firstName ) || is.na(contact $ lastName )){
205
214
zenodo_metadata $ addCreator(
206
215
name = contact $ organizationName ,
207
- affiliation = contact $ organizationName ,
216
+ affiliations = contact $ organizationName ,
208
217
orcid = orcid
209
218
)
210
219
}else {
211
220
zenodo_metadata $ addCreator(
212
221
firstname = contact $ firstName ,
213
222
lastname = contact $ lastName ,
214
- affiliation = contact $ organizationName ,
223
+ affiliations = contact $ organizationName ,
215
224
orcid = orcid
216
225
)
217
226
}
@@ -225,8 +234,8 @@ function(action, entity, config){
225
234
licenses <- entity $ rights [sapply(entity $ rights , function (x ){tolower(x $ key ) == " license" })]
226
235
if (length(licenses )> 0 ){
227
236
license <- licenses [[1 ]]$ values [[1 ]]
228
- accepted_licenses <- ZENODO $ getLicenses() $ id
229
- if (license %in% accepted_licenses ){
237
+ the_license <- ZENODO $ getLicenseById( license )
238
+ if (! is.null( the_license ) ){
230
239
zenodo_metadata $ setLicense(license , sandbox = ZENODO $ sandbox )
231
240
}else {
232
241
config $ logger.warn(sprintf(" Zenodo :license specified (%s) in entity doesn't match Zenodo accepted list of licenses. license %s ignored!" ,
@@ -236,35 +245,44 @@ function(action, entity, config){
236
245
}
237
246
238
247
# AccessRight
239
- # Access right with the following values: 'open','embargoed', 'restricted','closed'
248
+ zenodo_metadata $ setAccessPolicyRecord(" public" ) # always the case for Zenodo (at least for now)
249
+ # Access right with the following values: 'public','restricted'
240
250
if (length(entity $ rights )> 0 ){
241
251
accessRights <- entity $ rights [sapply(entity $ rights , function (x ){tolower(x $ key ) == " accessright" })]
242
252
config $ logger.info(sprintf(" accessRight: '%s'" , accessRights ))
243
253
if (length(accessRights )> 0 ){
244
254
accessRight <- accessRights [[1 ]]$ values [[1 ]]
245
255
config $ logger.info(sprintf(" accessRight Value: '%s'" , accessRight ))
246
- zenodo_metadata $ setAccessRight(accessRight )
247
- if (" embargoed" %in% accessRight ) {
248
- config $ logger.info(sprintf(" Embargoed! Looking for embargoed date..." ))
249
- embargoDates <- entity $ dates [sapply(entity $ dates , function (date ){date $ key == " embargo" })]
250
- embargoDate <- if (length(embargoDates )> 0 ) embargoDates [[1 ]]$ value else config $ logger.error(sprintf(" Zenodo: 'embargo' not set in entity$dates whereas 'embargoed' is set in entity$rights. Please check your entities !" ))
251
- zenodo_metadata $ setEmbargoDate(embargoDate )
256
+ zenodo_metadata $ setAccessPolicyFiles(accessRight )
257
+ if (accessRight == " restricted" ){
258
+ # manage embargo
259
+ embargoDates <- entity $ dates [sapply(entity $ dates , function (date ){date $ key == " embargo" })]
260
+ if (length(embargoDates )> 0 ){
261
+ embargoDate = embargoDates [[1 ]]$ value
262
+ config $ logger.info(sprintf(" Setting embargo date '%s'" , embargoDate ))
263
+ embargoReason = " "
264
+ embargoReasons = entity $ rights [sapply(entity $ rights , function (x ){tolower(x $ key ) == " embargoreason" })]
265
+ if (length(embargoReasons )> 0 ){
266
+ embargoReason = embargoReasons [[1 ]]$ values [[1 ]]
267
+ config $ logger.info(sprintf(" Setting embargo reason: %s" , embargoReason ))
252
268
}
253
- else if (" restricted" %in% accessRight ) {
254
- config $ logger.info(sprintf(" Restricted! :/ :/ Looking for accessConditions..." ))
255
- accessConditions <- entity $ rights [sapply(entity $ rights , function (x ){tolower(x $ key ) == " accessconditions" })][[1 ]]$ values [[1 ]]
256
- zenodo_metadata $ setAccessConditions(accessConditions )
269
+ zenodo_metadata $ setAccessPolicyEmbargo(active = TRUE , until = as.Date(embargoDate ), reason = embargoReason )
257
270
}
271
+ # access conditions
272
+ # TODO to review if available through new Zeonod API
273
+ # accessConditions <- entity$rights[sapply(entity$rights, function(x){tolower(x$key) == "accessconditions"})]
274
+ # if(length(accessConditions)>0){
275
+ # zenodo_metadata$setAccessConditions(accessConditions[[1]]$values[[1]])
276
+ # }
277
+ }
278
+ }else {
279
+ config $ logger.info(sprintf(" Zenodo: accessRight specified in entity not available. accessRight will be set to public!" ))
280
+ zenodo_metadata $ setAccessPolicyFiles(" public" )
258
281
}
259
- else {
260
- config $ logger.info(sprintf(" Zenodo: accessRight specified in entity not available. accessRight will be set to open!" ))
261
- zenodo_metadata $ setAccessRight(" open" )
262
- }
282
+ }else {
283
+ config $ logger.info(sprintf(" Zenodo: Rights is empty. accessRight will be set to public!" ))
284
+ zenodo_metadata $ setAccessPolicyFiles(" public" )
263
285
}
264
- else {
265
- config $ logger.info(sprintf(" Zenodo: Rights is empty. accessRight will be set to open!" ))
266
- zenodo_metadata $ setAccessRight(" open" )
267
- }
268
286
269
287
# references
270
288
if (length(entity $ relations )> 0 ){
@@ -290,17 +308,18 @@ function(action, entity, config){
290
308
}
291
309
292
310
# communities
293
- if (length(communities )> 0 ){
294
- zenodo_metadata $ metadata $ communities <- list ()
295
- for (community in communities ) if (! is.na(community )) zenodo_metadata $ addCommunity(community , sandbox = ZENODO $ sandbox )
296
- }
311
+ # TODO to analyze if this can be done with new Zenodo API
312
+ # if(length(communities)>0){
313
+ # zenodo_metadata$metadata$communities <- list()
314
+ # for(community in communities) if(!is.na(community)) zenodo_metadata$addCommunity(community, sandbox = ZENODO$sandbox)
315
+ # }
297
316
}else {
298
317
config $ logger.info(" Skipping update of Zenodo record metadata (option 'update_metadata' FALSE)" )
299
318
}
300
319
301
320
# file uploads (for new or edited records)
302
321
# note: for new versions this is managed directly with ZENODO$depositRecordVersion
303
- if (depositWithFiles & (! update | (update & update_files )) & record_state == " unsubmitted " ){
322
+ if (depositWithFiles & (! update | (update & update_files )) & record_status == " draft " & zenodo_metadata $ is_draft ){
304
323
if (deleteOldFiles & ! skipDataDownload ){
305
324
config $ logger.info(" Zenodo: deleting old files..." )
306
325
zen_files <- ZENODO $ getFiles(zenodo_metadata $ id )
@@ -375,10 +394,9 @@ function(action, entity, config){
375
394
}
376
395
}
377
396
config $ logger.info(sprintf(" Deposit record with id '%s' - publish = %s" , zenodo_metadata $ id , tolower(as.character(publish ))))
378
- out <- switch (record_state ,
379
- " unsubmitted" = ZENODO $ depositRecord(zenodo_metadata , publish = publish ),
380
- " inprogress" = ZENODO $ depositRecord(zenodo_metadata , publish = publish ),
381
- " done" = {
397
+ out <- switch (record_status ,
398
+ " draft" = ZENODO $ depositRecord(zenodo_metadata , publish = publish ),
399
+ " published" = {
382
400
switch (strategy ,
383
401
" edition" = ZENODO $ depositRecord(zenodo_metadata , publish = publish ),
384
402
" newversion" = {
@@ -417,21 +435,21 @@ function(action, entity, config){
417
435
}
418
436
419
437
# we set the (prereserved) doi to the entity in question
420
- doi_to_save <- try( out $ metadata $ prereserve_doi $ doi , silent = TRUE )
421
- if (is( doi_to_save , " try-error " )) doi_to_save <- entity $ identifiers [[" doi" ]]
422
- config $ logger.info(sprintf(" Setting DOI '%s' to save and export for record" ,out $ metadata $ prereserve_doi $ doi ))
438
+ doi_to_save <- out $ pids $ doi $ identifier
439
+ if (! is.null( entity $ identifiers [[ " doi " ]] )) doi_to_save <- entity $ identifiers [[" doi" ]]
440
+ config $ logger.info(sprintf(" Setting DOI '%s' to save and export for record" ,doi_to_save ))
423
441
for (i in 1 : length(config $ metadata $ content $ entities )){
424
442
ent <- config $ metadata $ content $ entities [[i ]]
425
443
if (ent $ identifiers [[" id" ]]== entity $ identifiers [[" id" ]]){
426
444
if (regexpr(" zenodo" , doi )> 0 ){
427
- config $ metadata $ content $ entities [[i ]]$ identifiers [[" zenodo_doi_to_save" ]] <- out $ metadata $ prereserve_doi $ doi
445
+ config $ metadata $ content $ entities [[i ]]$ identifiers [[" zenodo_doi_to_save" ]] <- out $ getDOI()
428
446
config $ metadata $ content $ entities [[i ]]$ identifiers [[" zenodo_conceptdoi_to_save" ]] <- out $ getConceptDOI()
429
447
config $ metadata $ content $ entities [[i ]]$ setStatus(" zenodo" , ifelse(publish , " published" , " draft" ))
430
448
}
431
449
break ;
432
450
}
433
451
}
434
- entity $ identifiers [[" zenodo_doi_to_save" ]] <- out $ metadata $ prereserve_doi $ doi
452
+ entity $ identifiers [[" zenodo_doi_to_save" ]] <- out $ getDOI()
435
453
entity $ identifiers [[" zenodo_conceptdoi_to_save" ]] <- out $ getConceptDOI()
436
454
entity $ setStatus(" zenodo" , ifelse(publish , " published" , " draft" ))
437
455
0 commit comments