Skip to content

Commit 5c62e77

Browse files
committed
support #387 testing back Zenodo action based on new Zenodo API
1 parent eaf54b8 commit 5c62e77

File tree

5 files changed

+100
-77
lines changed

5 files changed

+100
-77
lines changed

DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Suggests:
7171
d4storagehub4R,
7272
rmarkdown,
7373
dataverse
74+
Remotes:
75+
eblondel/zen4R
7476
License: MIT + file LICENSE
7577
URL: https://github.com/r-geoflow/geoflow
7678
BugReports: https://github.com/r-geoflow/geoflow

doc/Summary_metadata.csv

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
"Date","edition",,,"x",,,,,,,,
2323
"Date","embargo",,,,,,,,"x",,,
2424
"Type","generic",,,"x",,,,,"x",,"x",
25-
"Type","zenodoUploadType",,,,,,,,"x",,,
26-
"Type","zenodoPublicationType",,,,,,,,"x",,,
27-
"Type","zenodoImageType",,,,,,,,"x",,,
25+
"Type","zenodoResourceType",,,,,,,,"x",,,
2826
"Language",,,,"x",,,,,,"x",,
2927
"SpatialCoverage","ewkt",,,"x",,,,"x",,,,
3028
"SpatialCoverage","wkt",,,"x",,,,"x",,,,
@@ -48,6 +46,7 @@
4846
"Rights","license","x","x","x",,,,,"x","x",,"x"
4947
"Rights","accessRight",,,,,,,,"x",,,
5048
"Rights","accessConditions",,,,,,,,"x",,,
49+
"Rights","embargoReason",,,,,,,,"x",,,
5150
"Provenance","statement","x","x","x",,,,,,,,
5251
"Provenance","process","x","x","x",,,,,,,,
5352
"Format","ressource",,,"x",,,,,,,,

inst/actions/zen4R_deposit_record.R

Lines changed: 91 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function(action, entity, config){
4141
#if nothing is found, we use the default get depositions by identifier, used if no DOI is specified
4242
#this approach is possible because the Zenodo record has a related identifier as URN, specified when
4343
#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
4545
deposits <- NULL
4646
if(!is.null(entity$identifiers[["doi"]])){
4747
#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){
6868
related_identifiers <- deposit$metadata$related_identifiers
6969
if(!is.null(related_identifiers)){
7070
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"){
7574
zenodo_metadata <<- deposit
7675
break
7776
}
@@ -86,23 +85,34 @@ function(action, entity, config){
8685

8786
#action to perform: create empty record or update existing record
8887
update <- FALSE
89-
record_state <- NULL
88+
record_status <- NULL
9089
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"]]))
9291
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)
9497
if("bucket" %in% names(zenodo_metadata$links)){
9598
entity$addResource("zenodo_bucket", zenodo_metadata$links$bucket) #attempt to keep bucket since zenodo seems not to retrieve always bucket link
9699
}
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
99106
}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"]]))
101108
update <- TRUE
102-
record_state <- zenodo_metadata$state
109+
record_status <- zenodo_metadata$status
103110

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"){
106116
config$logger.info(sprintf("Zenodo: record '%s' already published. Need to unlock it for edition", zenodo_metadata$id))
107117
unlocked_rec <- ZENODO$editRecord(zenodo_metadata$id)
108118
if(is(unlocked_rec, "ZenodoRecord")){
@@ -116,7 +126,7 @@ function(action, entity, config){
116126
}
117127
}
118128

119-
doi <- zenodo_metadata$metadata$prereserve_doi$doi
129+
doi <- zenodo_metadata$pids$doi$identifier
120130

121131
#if entity already comes with a DOI, we set it (this might be a preset DOI from Zenodo or elsewhere)
122132
if(!is.null(entity$identifiers[["doi"]])){
@@ -138,20 +148,20 @@ function(action, entity, config){
138148
}
139149
#basic record description
140150
zenodo_metadata$setTitle(entity$titles[["title"]])
151+
if(!is.null(entity$titles[["alternative"]])){
152+
zenodo_metadata$addAdditionalTitle(entity$titles[["alternative"]], type = "alternative-title")
153+
}
141154
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+
144159
#keywords (free text) & subjects
145160
zenodo_metadata$metadata$keywords <- list()
146161
zenodo_metadata$metadata$subjects <- list()
147162
for(subject in entity$subjects){
148163
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)
155165
}
156166
}
157167

@@ -164,20 +174,19 @@ function(action, entity, config){
164174
if(!is.null(edition)){
165175
zenodo_metadata$setVersion(edition)
166176
}
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"]])
171181

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)
181190
}
182191

183192
#creators
@@ -204,14 +213,14 @@ function(action, entity, config){
204213
if(is.na(contact$firstName) || is.na(contact$lastName)){
205214
zenodo_metadata$addCreator(
206215
name = contact$organizationName,
207-
affiliation = contact$organizationName,
216+
affiliations = contact$organizationName,
208217
orcid = orcid
209218
)
210219
}else{
211220
zenodo_metadata$addCreator(
212221
firstname = contact$firstName,
213222
lastname = contact$lastName,
214-
affiliation = contact$organizationName,
223+
affiliations = contact$organizationName,
215224
orcid = orcid
216225
)
217226
}
@@ -225,8 +234,8 @@ function(action, entity, config){
225234
licenses <- entity$rights[sapply(entity$rights, function(x){tolower(x$key) == "license"})]
226235
if(length(licenses)>0){
227236
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)){
230239
zenodo_metadata$setLicense(license, sandbox = ZENODO$sandbox)
231240
}else{
232241
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){
236245
}
237246

238247
# 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'
240250
if(length(entity$rights)>0){
241251
accessRights <- entity$rights[sapply(entity$rights, function(x){tolower(x$key) == "accessright"})]
242252
config$logger.info(sprintf("accessRight: '%s'", accessRights))
243253
if(length(accessRights)>0){
244254
accessRight <- accessRights[[1]]$values[[1]]
245255
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))
252268
}
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)
257270
}
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")
258281
}
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")
263285
}
264-
else{
265-
config$logger.info(sprintf("Zenodo: Rights is empty. accessRight will be set to open!"))
266-
zenodo_metadata$setAccessRight("open")
267-
}
268286

269287
#references
270288
if(length(entity$relations)>0){
@@ -290,17 +308,18 @@ function(action, entity, config){
290308
}
291309

292310
#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+
# }
297316
}else{
298317
config$logger.info("Skipping update of Zenodo record metadata (option 'update_metadata' FALSE)")
299318
}
300319

301320
#file uploads (for new or edited records)
302321
#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){
304323
if(deleteOldFiles & !skipDataDownload){
305324
config$logger.info("Zenodo: deleting old files...")
306325
zen_files <- ZENODO$getFiles(zenodo_metadata$id)
@@ -375,10 +394,9 @@ function(action, entity, config){
375394
}
376395
}
377396
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" = {
382400
switch(strategy,
383401
"edition" = ZENODO$depositRecord(zenodo_metadata, publish = publish),
384402
"newversion" = {
@@ -417,21 +435,21 @@ function(action, entity, config){
417435
}
418436

419437
#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))
423441
for(i in 1:length(config$metadata$content$entities)){
424442
ent <- config$metadata$content$entities[[i]]
425443
if(ent$identifiers[["id"]]==entity$identifiers[["id"]]){
426444
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()
428446
config$metadata$content$entities[[i]]$identifiers[["zenodo_conceptdoi_to_save"]] <- out$getConceptDOI()
429447
config$metadata$content$entities[[i]]$setStatus("zenodo", ifelse(publish, "published", "draft"))
430448
}
431449
break;
432450
}
433451
}
434-
entity$identifiers[["zenodo_doi_to_save"]] <- out$metadata$prereserve_doi$doi
452+
entity$identifiers[["zenodo_doi_to_save"]] <- out$getDOI()
435453
entity$identifiers[["zenodo_conceptdoi_to_save"]] <- out$getConceptDOI()
436454
entity$setStatus("zenodo", ifelse(publish, "published", "draft"))
437455

inst/extdata/workflows/config_metadata_gsheets_zenodo.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"logos": [
88
"https://via.placeholder.com/300x150.png/09f/fff?text=geoflow"
99
],
10-
"mode": "entity"
10+
"mode": "entity",
11+
"options": {
12+
"skipEnrichWithDatatypes": true
13+
}
1114
},
1215
"metadata": {
1316
"entities": [

tests/testthat/test_config_metadata_gsheets_zenodo.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ test_that("debug",{
3434
expect_equal(names(DEBUG), c("config", "entity"))
3535
expect_is(DEBUG$config, "list")
3636
expect_is(DEBUG$entity, "geoflow_entity")
37+
closeWorkflow(DEBUG$config)
3738
})
3839

3940
#execute

0 commit comments

Comments
 (0)