diff --git a/DESCRIPTION b/DESCRIPTION index fbdb1c7..1cf7d7e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: zen4R Version: 0.10 -Date: 2024-05-24 +Date: 2024-05-27 Title: Interface to 'Zenodo' REST API Authors@R: c( person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "emmanuel.blondel1@gmail.com", comment = c(ORCID = "0000-0002-5870-5762")), diff --git a/R/ZenodoManager.R b/R/ZenodoManager.R index 11531be..9c39ae5 100644 --- a/R/ZenodoManager.R +++ b/R/ZenodoManager.R @@ -443,7 +443,8 @@ ZenodoManager <- R6Class("ZenodoManager", return(out) }, - #'@description Submit a record to one or more community + + #'@description Submit a published record to one or more community #'@param record an object of class \link{ZenodoRecord} #'@param communities communities to which the record will be submitted #'@param message message to send to the community curator(s), either a text or a named list @@ -597,6 +598,127 @@ ZenodoManager <- R6Class("ZenodoManager", return(out) }, + #Reviews + #--------------------------------------------------------------------------- + #'@description Creates a record review request in a community + #'@param record an object of class \link{ZenodoRecord} + #'@param community a community to which the record is submitted for review and publication + #'@return a review request object of class \code{list}, or NULL if nothing was submitted + createReviewRequest = function(record, community){ + + zen_com = self$getCommunityById(community) + if(is.null(zen_com)){ + warnMsg = sprintf("Community '%s' does not exist in Zenodo! Aborting review request...", community) + cli::cli_alert_warning(warnMsg) + self$WARN(warnMsg) + return(NULL) + } + + review_payload = list(receiver = list(community = zen_com$id), type = "community-submission") + zenReq <- ZenodoRequest$new(private$url, "PUT", sprintf("records/%s/draft/review",record$id), + accept = "application/json", data = review_payload, + token= self$getToken(), + logger = self$loggerType) + zenReq$execute() + out <- zenReq$getResponse() + if(zenReq$getStatus() == 200){ + infoMsg = sprintf("Successfully created request to review record %s in community '%s'", + record$id, community) + cli::cli_alert_success(infoMsg) + self$INFO(infoMsg) + }else{ + errMsg = sprintf("Error while creating request to review record %s in comunity '%s':", + record$id, community) + print(out) + cli::cli_alert_danger(errMsg) + self$ERROR(errMsg) + out <- NULL + } + return(out) + }, + + #'@description Get a record review request + #'@param record an object of class \link{ZenodoRecord} + #'@return a review request object of class \code{list}, or NULL if nothing exists + getReviewRequest = function(record){ + + zenReq <- ZenodoRequest$new(private$url, "GET", sprintf("records/%s/draft/review",record$id), + accept = "application/json", + token= self$getToken(), + logger = self$loggerType) + zenReq$execute() + out <- zenReq$getResponse() + if(zenReq$getStatus() == 200){ + infoMsg = sprintf("Successfully fetched request to review record %s", record$id) + cli::cli_alert_success(infoMsg) + self$INFO(infoMsg) + }else{ + errMsg = sprintf("Error while fetching request to review record %s:", record$id) + print(out) + cli::cli_alert_danger(errMsg) + self$ERROR(errMsg) + out <- NULL + } + return(out) + }, + + #'@description Deletes a review request + #'@param record an object of class \link{ZenodoRecord} + #'@return \code{TRUE} if deleted, \code{FALSE} otherwise + deleteReviewRequest = function(record){ + + zenReq <- ZenodoRequest$new(private$url, "DELETE", sprintf("records/%s/draft/review",record$id), + accept = "application/json", + token= self$getToken(), + logger = self$loggerType) + zenReq$execute() + out <- NULL + if(zenReq$getStatus() == 204){ + infoMsg = sprintf("Successfully deleted request to review record %s", record$id) + cli::cli_alert_success(infoMsg) + self$INFO(infoMsg) + out <- TRUE + }else{ + errMsg = sprintf("Error while deleting request to review record %s:", record$id) + cli::cli_alert_danger(errMsg) + self$ERROR(errMsg) + out <- FALSE + } + return(out) + }, + + #'@description Submits a record for review. Prior to this submission, a community + #'has to be selected for a record. This is done by using the method \code{createReviewRequest(record, community)}. + #'@param recordId the ID of a Zenodo record + #'@param message message content for the submission. Optional + #'@return \code{TRUE} if submitted, \code{FALSE} otherwise + submitRecordForReview = function(recordId, message = NULL){ + out = NULL + submit_payload = list() + if(!is.null(message)){ + submit_payload = list(payload = list(content = message, format = "html")) + } + zenReq <- ZenodoRequest$new(private$url, "POST", sprintf("records/%s/draft/actions/submit-review", recordId), + accept = "application/json", data = submit_payload, + token = self$getToken(), + logger = self$loggerType) + zenReq$execute() + out = FALSE + if(zenReq$getStatus() == 202){ + infoMsg = sprintf("Successfully submitted record %s for review", recordId) + cli::cli_alert_success(infoMsg) + self$INFO(infoMsg) + out = TRUE + }else{ + errMsg = sprintf("Error while submitting record %s for review:",recordId) + print(out) + cli::cli_alert_danger(errMsg) + self$ERROR(errMsg) + out <- FALSE + } + return(out) + }, + #Special vocabulary/Awards (former Grants) #------------------------------------------------------------------------------------------ diff --git a/man/ZenodoManager.Rd b/man/ZenodoManager.Rd index 13198eb..fdb3d12 100644 --- a/man/ZenodoManager.Rd +++ b/man/ZenodoManager.Rd @@ -102,6 +102,10 @@ Emmanuel Blondel \item \href{#method-ZenodoManager-submitRecordToCommunities}{\code{ZenodoManager$submitRecordToCommunities()}} \item \href{#method-ZenodoManager-removeRecordFromCommunities}{\code{ZenodoManager$removeRecordFromCommunities()}} \item \href{#method-ZenodoManager-getRecordCommunities}{\code{ZenodoManager$getRecordCommunities()}} +\item \href{#method-ZenodoManager-createReviewRequest}{\code{ZenodoManager$createReviewRequest()}} +\item \href{#method-ZenodoManager-getReviewRequest}{\code{ZenodoManager$getReviewRequest()}} +\item \href{#method-ZenodoManager-deleteReviewRequest}{\code{ZenodoManager$deleteReviewRequest()}} +\item \href{#method-ZenodoManager-submitRecordForReview}{\code{ZenodoManager$submitRecordForReview()}} \item \href{#method-ZenodoManager-getGrants}{\code{ZenodoManager$getGrants()}} \item \href{#method-ZenodoManager-getAwards}{\code{ZenodoManager$getAwards()}} \item \href{#method-ZenodoManager-getGrantsByName}{\code{ZenodoManager$getGrantsByName()}} @@ -387,7 +391,7 @@ the community \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZenodoManager-submitRecordToCommunities}{}}} \subsection{Method \code{submitRecordToCommunities()}}{ -Submit a record to one or more community +Submit a published record to one or more community \subsection{Usage}{ \if{html}{\out{
}}\preformatted{ZenodoManager$submitRecordToCommunities( record, @@ -455,6 +459,91 @@ the list of communities in which the record was included } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoManager-createReviewRequest}{}}} +\subsection{Method \code{createReviewRequest()}}{ +Creates a record review request in a community +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ZenodoManager$createReviewRequest(record, community)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{record}}{an object of class \link{ZenodoRecord}} + +\item{\code{community}}{a community to which the record is submitted for review and publication} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +a review request object of class \code{list}, or NULL if nothing was submitted +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoManager-getReviewRequest}{}}} +\subsection{Method \code{getReviewRequest()}}{ +Get a record review request +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ZenodoManager$getReviewRequest(record)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{record}}{an object of class \link{ZenodoRecord}} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +a review request object of class \code{list}, or NULL if nothing exists +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoManager-deleteReviewRequest}{}}} +\subsection{Method \code{deleteReviewRequest()}}{ +Deletes a review request +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ZenodoManager$deleteReviewRequest(record)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{record}}{an object of class \link{ZenodoRecord}} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +\code{TRUE} if deleted, \code{FALSE} otherwise +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoManager-submitRecordForReview}{}}} +\subsection{Method \code{submitRecordForReview()}}{ +Submits a record for review. Prior to this submission, a community +has to be selected for a record. This is done by using the method \code{createReviewRequest(record, community)}. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ZenodoManager$submitRecordForReview(recordId, message = NULL)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{recordId}}{the ID of a Zenodo record} + +\item{\code{message}}{message content for the submission. Optional} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +\code{TRUE} if submitted, \code{FALSE} otherwise +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZenodoManager-getGrants}{}}} \subsection{Method \code{getGrants()}}{