From 21618e8a08788d645f22a43416e46408d0d3071a Mon Sep 17 00:00:00 2001 From: eblondel Date: Tue, 14 May 2024 18:02:10 +0200 Subject: [PATCH] #133 fix getDepositionbyConceptId, #137 getId, getConceptId, getDOI, getConceptDOI methods --- R/ZenodoManager.R | 2 +- R/ZenodoRecord.R | 95 ++++++++++------- man/ZenodoRecord.Rd | 241 ++++++++++++++++++++++---------------------- 3 files changed, 178 insertions(+), 160 deletions(-) diff --git a/R/ZenodoManager.R b/R/ZenodoManager.R index 287d854..7aa9369 100644 --- a/R/ZenodoManager.R +++ b/R/ZenodoManager.R @@ -1075,7 +1075,7 @@ ZenodoManager <- R6Class("ZenodoManager", result <- self$getDepositions(q = query, all_versions = TRUE, exact = TRUE) if(length(result)>0){ result <- result[[1]] - if(result$conceptrecid == conceptrecid){ + if(result$getConceptId() == conceptrecid){ infoMsg = sprintf("Successfully fetched record for concept id '%s'!",conceptrecid) cli::cli_alert_success(infoMsg) self$INFO(infoMsg) diff --git a/R/ZenodoRecord.R b/R/ZenodoRecord.R index c29290c..efd66e8 100644 --- a/R/ZenodoRecord.R +++ b/R/ZenodoRecord.R @@ -132,6 +132,55 @@ ZenodoRecord <- R6Class("ZenodoRecord", #Invenio RDM API new methods #--------------------------------------------------------------------------- + #ID methods + #--------------------------------------------------------------------------- + + #'@description Get the record Id + #'@return the Id, object of class \code{character} + getId = function(){ + return(self$id) + }, + + #'@description Get the concept record Id + #'@return the concept Id, object of class \code{character} + getConceptId = function(){ + conceptid = as(self$getId(), "integer") - self$versions$index + return(as.character(conceptid)) + }, + + #DOI methods + #--------------------------------------------------------------------------- + + #' @description Set the DOI. This method can be used if a DOI has been already assigned outside Zenodo. + #' @param doi DOI to set for the record + #' @param provider DOI provider + #' @param client DOI client + setDOI = function(doi, provider = NULL, client = NULL){ + self$pids = list(doi = list(identifier = doi, provider = provider, client = client)) + }, + + #'@description Get the record DOI. + #'@return the DOI, object of class \code{character} + getDOI = function(){ + return(self$pids$doi$identifier) + }, + + #' @description Get the concept (generic) DOI. The concept DOI is a generic DOI + #' common to all versions of a Zenodo record. + #' @return the concept DOI, object of class \code{character} + getConceptDOI = function(){ + conceptdoi = NULL + doi <- self$pids$doi$identifier + if(!is.null(doi)) if(regexpr("zenodo", doi)>0){ + doi_parts <- unlist(strsplit(doi, "zenodo.")) + conceptdoi <- paste0(doi_parts[1], "zenodo.", self$getConceptId()) + } + return(conceptdoi) + }, + + #Access methods + #--------------------------------------------------------------------------- + #'@description Set the access policy for record, among values "public" (default) or "restricted" #'@param access access policy ('public' or 'restricted') setAccessPolicyRecord = function(access = c("public","resticted")){ @@ -153,13 +202,8 @@ ZenodoRecord <- R6Class("ZenodoRecord", self$access$embargo = list(active = active, until = until, reason = reason) }, - #' @description Set the DOI. This method can be used if a DOI has been already assigned outside Zenodo. - #' @param doi DOI to set for the record - #' @param provider DOI provider - #' @param client DOI client - setDOI = function(doi, provider = NULL, client = NULL){ - self$pids = list(doi = list(identifier = doi, provider = provider, client = client)) - }, + #Resource type methods + #--------------------------------------------------------------------------- #' @description Set the resource type (mandatory). #' @param resourceType record resource type @@ -200,6 +244,9 @@ ZenodoRecord <- R6Class("ZenodoRecord", self$WARN(warnMsg) }, + #Publication-related methods + #--------------------------------------------------------------------------- + #' @description Set the publisher #' @param publisher publisher object of class \code{character} setPublisher = function(publisher){ @@ -252,6 +299,9 @@ ZenodoRecord <- R6Class("ZenodoRecord", return(removed) }, + #Description methods + #--------------------------------------------------------------------------- + #' @description Set the record title. #' @param title object of class \code{character} setTitle = function(title){ @@ -264,25 +314,6 @@ ZenodoRecord <- R6Class("ZenodoRecord", self$metadata$description <- description }, - #' @description Set the access right. - #' @param accessRight record access right among the following values: 'open','embargoed', 'restricted','closed' - setAccessRight = function(accessRight){ - accessRightValues <- c("open","embargoed","restricted","closed") - if(!(accessRight %in% accessRightValues)){ - errorMsg <- sprintf("The access right should be among the values [%s", - paste(accessRightValues, collapse=",")) - self$ERROR(errorMsg) - stop(errorMsg) - } - self$metadata$access_right <- accessRight - }, - - #' @description set the access conditions. - #' @param accessConditions object of class \code{character} - setAccessConditions = function(accessConditions){ - self$metadata$access_conditions <- accessConditions - }, - # PERSON OR ORG #--------------------------------------------------------------------------- @@ -1471,18 +1502,6 @@ ZenodoRecord <- R6Class("ZenodoRecord", #legacy REST API methods (to be evaluated under Zenodo Invenio RDM migration) #---------------------------------------------------------------------------- - #' @description Get the concept (generic) DOI. The concept DOI is a generic DOI - #' common to all versions of a Zenodo record. - #' @return the concept DOI, object of class \code{character} - getConceptDOI = function(){ - doi <- self$pids$doi$identifier - if(!is.null(doi)) { - doi_parts <- unlist(strsplit(doi, "zenodo.")) - conceptrec <- paste0(doi_parts[1], "zenodo.", self$conceptrecid) - } - return(conceptdoi) - }, - #' @description Get DOI of the first record version. #' @return the first DOI, object of class \code{character} getFirstDOI = function(){ diff --git a/man/ZenodoRecord.Rd b/man/ZenodoRecord.Rd index 1ccf0a7..6c8a550 100644 --- a/man/ZenodoRecord.Rd +++ b/man/ZenodoRecord.Rd @@ -35,25 +35,19 @@ Emmanuel Blondel \describe{ \item{\code{created}}{record creation date} -\item{\code{access}}{access policies} - -\item{\code{conceptdoi}}{record Concept DOI (common to all record versions)} - -\item{\code{conceptrecid}}{record concept id} +\item{\code{updated}}{record update date} -\item{\code{modified}}{record modification date} +\item{\code{revision_id}}{revision id} -\item{\code{owners}}{record owners} +\item{\code{is_draft}}{is draft} -\item{\code{recid}}{recid} +\item{\code{is_published}}{is published} \item{\code{status}}{record status} -\item{\code{state}}{record state} +\item{\code{versions}}{versions} -\item{\code{submitted}}{record submission status} - -\item{\code{revision}}{record revision} +\item{\code{access}}{access policies} \item{\code{files}}{list of files associated to the record} @@ -76,14 +70,14 @@ Emmanuel Blondel \itemize{ \item \href{#method-ZenodoRecord-new}{\code{ZenodoRecord$new()}} \item \href{#method-ZenodoRecord-getStats}{\code{ZenodoRecord$getStats()}} +\item \href{#method-ZenodoRecord-getId}{\code{ZenodoRecord$getId()}} +\item \href{#method-ZenodoRecord-getConceptId}{\code{ZenodoRecord$getConceptId()}} +\item \href{#method-ZenodoRecord-setDOI}{\code{ZenodoRecord$setDOI()}} +\item \href{#method-ZenodoRecord-getDOI}{\code{ZenodoRecord$getDOI()}} +\item \href{#method-ZenodoRecord-getConceptDOI}{\code{ZenodoRecord$getConceptDOI()}} \item \href{#method-ZenodoRecord-setAccessPolicyRecord}{\code{ZenodoRecord$setAccessPolicyRecord()}} \item \href{#method-ZenodoRecord-setAccessPolicyFiles}{\code{ZenodoRecord$setAccessPolicyFiles()}} \item \href{#method-ZenodoRecord-setAccessPolicyEmbargo}{\code{ZenodoRecord$setAccessPolicyEmbargo()}} -\item \href{#method-ZenodoRecord-setDOI}{\code{ZenodoRecord$setDOI()}} -\item \href{#method-ZenodoRecord-getConceptDOI}{\code{ZenodoRecord$getConceptDOI()}} -\item \href{#method-ZenodoRecord-getFirstDOI}{\code{ZenodoRecord$getFirstDOI()}} -\item \href{#method-ZenodoRecord-getLastDOI}{\code{ZenodoRecord$getLastDOI()}} -\item \href{#method-ZenodoRecord-getVersions}{\code{ZenodoRecord$getVersions()}} \item \href{#method-ZenodoRecord-setResourceType}{\code{ZenodoRecord$setResourceType()}} \item \href{#method-ZenodoRecord-setUploadType}{\code{ZenodoRecord$setUploadType()}} \item \href{#method-ZenodoRecord-setPublicationType}{\code{ZenodoRecord$setPublicationType()}} @@ -94,8 +88,6 @@ Emmanuel Blondel \item \href{#method-ZenodoRecord-removeDate}{\code{ZenodoRecord$removeDate()}} \item \href{#method-ZenodoRecord-setTitle}{\code{ZenodoRecord$setTitle()}} \item \href{#method-ZenodoRecord-setDescription}{\code{ZenodoRecord$setDescription()}} -\item \href{#method-ZenodoRecord-setAccessRight}{\code{ZenodoRecord$setAccessRight()}} -\item \href{#method-ZenodoRecord-setAccessConditions}{\code{ZenodoRecord$setAccessConditions()}} \item \href{#method-ZenodoRecord-addPersonOrOrg}{\code{ZenodoRecord$addPersonOrOrg()}} \item \href{#method-ZenodoRecord-removePersonOrOrg}{\code{ZenodoRecord$removePersonOrOrg()}} \item \href{#method-ZenodoRecord-addCreator}{\code{ZenodoRecord$addCreator()}} @@ -175,6 +167,9 @@ Emmanuel Blondel \item \href{#method-ZenodoRecord-downloadFiles}{\code{ZenodoRecord$downloadFiles()}} \item \href{#method-ZenodoRecord-print}{\code{ZenodoRecord$print()}} \item \href{#method-ZenodoRecord-toDCEntry}{\code{ZenodoRecord$toDCEntry()}} +\item \href{#method-ZenodoRecord-getFirstDOI}{\code{ZenodoRecord$getFirstDOI()}} +\item \href{#method-ZenodoRecord-getLastDOI}{\code{ZenodoRecord$getLastDOI()}} +\item \href{#method-ZenodoRecord-getVersions}{\code{ZenodoRecord$getVersions()}} \item \href{#method-ZenodoRecord-clone}{\code{ZenodoRecord$clone()}} } } @@ -224,58 +219,29 @@ statistics as \code{data.frame} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-setAccessPolicyRecord}{}}} -\subsection{Method \code{setAccessPolicyRecord()}}{ -Set the access policy for record, among values "public" (default) or "restricted" +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-getId}{}}} +\subsection{Method \code{getId()}}{ +Get the record Id \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$setAccessPolicyRecord(access = c("public", "resticted"))}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$getId()}\if{html}{\out{
}} } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{access}}{access policy ('public' or 'restricted')} -} -\if{html}{\out{
}} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-setAccessPolicyFiles}{}}} -\subsection{Method \code{setAccessPolicyFiles()}}{ -Set the access policy for files, among values "public" (default) or "restricted" -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$setAccessPolicyFiles(access = c("public", "resticted"))}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{access}}{access policy ('public' or 'restricted')} -} -\if{html}{\out{
}} +\subsection{Returns}{ +the Id, object of class \code{character} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-setAccessPolicyEmbargo}{}}} -\subsection{Method \code{setAccessPolicyEmbargo()}}{ -Set access policy embargo options +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-getConceptId}{}}} +\subsection{Method \code{getConceptId()}}{ +Get the concept record Id \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$setAccessPolicyEmbargo(active = FALSE, until = NULL, reason = "")}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$getConceptId()}\if{html}{\out{
}} } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{active}}{whether embargo is active or not. Default is \code{FALSE}} - -\item{\code{until}}{embargo date, object of class \code{Date}. Default is \code{NULL}. Must be provided if embargo is active} - -\item{\code{reason}}{embargo reason, object of class \code{character}. Default is an empty string} -} -\if{html}{\out{
}} +\subsection{Returns}{ +the concept Id, object of class \code{character} } } \if{html}{\out{
}} @@ -300,12 +266,24 @@ Set the DOI. This method can be used if a DOI has been already assigned outside } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-getDOI}{}}} +\subsection{Method \code{getDOI()}}{ +Get the record DOI. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ZenodoRecord$getDOI()}\if{html}{\out{
}} +} + +\subsection{Returns}{ +the DOI, object of class \code{character} +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZenodoRecord-getConceptDOI}{}}} \subsection{Method \code{getConceptDOI()}}{ -Get the concept (generic) DOI. The concept DOI is a generic DOI common to all versions - of a Zenodo record. When a deposit is unsubmitted, this concept DOI is inherited based - on the prereserved DOI of the first record version. +Get the concept (generic) DOI. The concept DOI is a generic DOI +common to all versions of a Zenodo record. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{ZenodoRecord$getConceptDOI()}\if{html}{\out{
}} } @@ -315,43 +293,58 @@ the concept DOI, object of class \code{character} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-getFirstDOI}{}}} -\subsection{Method \code{getFirstDOI()}}{ -Get DOI of the first record version. +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-setAccessPolicyRecord}{}}} +\subsection{Method \code{setAccessPolicyRecord()}}{ +Set the access policy for record, among values "public" (default) or "restricted" \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$getFirstDOI()}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$setAccessPolicyRecord(access = c("public", "resticted"))}\if{html}{\out{
}} } -\subsection{Returns}{ -the first DOI, object of class \code{character} +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{access}}{access policy ('public' or 'restricted')} +} +\if{html}{\out{
}} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-getLastDOI}{}}} -\subsection{Method \code{getLastDOI()}}{ -Get DOI of the latest record version. +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-setAccessPolicyFiles}{}}} +\subsection{Method \code{setAccessPolicyFiles()}}{ +Set the access policy for files, among values "public" (default) or "restricted" \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$getLastDOI()}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$setAccessPolicyFiles(access = c("public", "resticted"))}\if{html}{\out{
}} } -\subsection{Returns}{ -the last DOI, object of class \code{character} +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{access}}{access policy ('public' or 'restricted')} +} +\if{html}{\out{
}} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-getVersions}{}}} -\subsection{Method \code{getVersions()}}{ -Get record versions with creation/publication date, - version (ordering number) and DOI. +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-setAccessPolicyEmbargo}{}}} +\subsection{Method \code{setAccessPolicyEmbargo()}}{ +Set access policy embargo options \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$getVersions()}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$setAccessPolicyEmbargo(active = FALSE, until = NULL, reason = "")}\if{html}{\out{
}} } -\subsection{Returns}{ -a \code{data.frame} with the record versions +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{active}}{whether embargo is active or not. Default is \code{FALSE}} + +\item{\code{until}}{embargo date, object of class \code{Date}. Default is \code{NULL}. Must be provided if embargo is active} + +\item{\code{reason}}{embargo reason, object of class \code{character}. Default is an empty string} +} +\if{html}{\out{
}} } } \if{html}{\out{
}} @@ -541,40 +534,6 @@ Set the record description } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-setAccessRight}{}}} -\subsection{Method \code{setAccessRight()}}{ -Set the access right. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$setAccessRight(accessRight)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{accessRight}}{record access right among the following values: 'open','embargoed', 'restricted','closed'} -} -\if{html}{\out{
}} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-setAccessConditions}{}}} -\subsection{Method \code{setAccessConditions()}}{ -set the access conditions. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$setAccessConditions(accessConditions)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{accessConditions}}{object of class \code{character}} -} -\if{html}{\out{
}} -} -} -\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZenodoRecord-addPersonOrOrg}{}}} \subsection{Method \code{addPersonOrOrg()}}{ @@ -2265,6 +2224,46 @@ an object of class \code{DCEntry} } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-getFirstDOI}{}}} +\subsection{Method \code{getFirstDOI()}}{ +Get DOI of the first record version. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ZenodoRecord$getFirstDOI()}\if{html}{\out{
}} +} + +\subsection{Returns}{ +the first DOI, object of class \code{character} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-getLastDOI}{}}} +\subsection{Method \code{getLastDOI()}}{ +Get DOI of the latest record version. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ZenodoRecord$getLastDOI()}\if{html}{\out{
}} +} + +\subsection{Returns}{ +the last DOI, object of class \code{character} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-getVersions}{}}} +\subsection{Method \code{getVersions()}}{ +Get record versions with creation/publication date, + version (ordering number) and DOI. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ZenodoRecord$getVersions()}\if{html}{\out{
}} +} + +\subsection{Returns}{ +a \code{data.frame} with the record versions +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZenodoRecord-clone}{}}} \subsection{Method \code{clone()}}{