Skip to content

Commit

Permalink
#56 getVersions consolidation
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Oct 15, 2021
1 parent d0fc4e3 commit 4a1425c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
7 changes: 7 additions & 0 deletions R/ZenodoManager.R
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,13 @@ ZenodoManager <- R6Class("ZenodoManager",
self$INFO(sprintf("Try to get deposition by Zenodo specific record id '%s'", conceptrecid))
conceptrec <- self$getDepositionByConceptId(conceptrecid)
last_doi <- tail(conceptrec$getVersions(),1L)$doi
if(length(last_doi)==0) {
if(nzchar(conceptrec$metadata$doi)){
last_doi = conceptrec$metadata$doi
}else{
last_doi = conceptrec$metadata$prereserve_doi$doi
}
}
result <- self$getDepositionByDOI(last_doi)
}
}
Expand Down
37 changes: 24 additions & 13 deletions R/ZenodoRecord.R
Original file line number Diff line number Diff line change
Expand Up @@ -444,23 +444,34 @@ ZenodoRecord <- R6Class("ZenodoRecord",
locale <- Sys.getlocale("LC_TIME")
Sys.setlocale("LC_TIME", "us_US")

zenodo_url <- paste0(unlist(strsplit(self$links$latest_html, "/record"))[1],"/api")
record_type <- if(self$state == "done") "record" else if(self$state == "unsubmitted") "deposit"
ref_link <- if(record_type == "record") "latest_html" else if(record_type == "deposit") "latest_draft_html"
zenodo_url <- paste0(unlist(strsplit(self$links[[ref_link]], paste0("/", record_type)))[1],"/api")
zenodo <- ZenodoManager$new(url = zenodo_url)

records <- zenodo$getRecords(q = sprintf("conceptrecid:%s", self$conceptrecid), all_versions = T)

versions <- do.call("rbind", lapply(records, function(version){
return(data.frame(
created = as.POSIXct(version$created, format = "%Y-%m-%dT%H:%M:%OS"),
date = as.Date(version$metadata$publication_date),
version = 0L,
doi = version$doi,
stringsAsFactors = FALSE
))
}))
versions <- versions[order(versions$created),]
row.names(versions) <- 1:nrow(versions)
versions$version <- 1:nrow(versions)
versions <- data.frame(
created = character(0),
date = character(0),
version = character(0),
doi = character(0),
stringsAsFactors = FALSE
)
if(length(records)>0){
versions = do.call("rbind", lapply(records, function(version){
return(data.frame(
created = as.POSIXct(version$created, format = "%Y-%m-%dT%H:%M:%OS"),
date = as.Date(version$metadata$publication_date),
version = 0L,
doi = version$doi,
stringsAsFactors = FALSE
))
}))
versions <- versions[order(versions$created),]
row.names(versions) <- 1:nrow(versions)
versions$version <- 1:nrow(versions)
}
Sys.setlocale("LC_TIME", locale)

return(versions)
Expand Down

0 comments on commit 4a1425c

Please sign in to comment.