diff --git a/R/ZenodoRecord.R b/R/ZenodoRecord.R index 182e188..6f2e6c1 100644 --- a/R/ZenodoRecord.R +++ b/R/ZenodoRecord.R @@ -16,6 +16,8 @@ ZenodoRecord <- R6Class("ZenodoRecord", "registrationauthority", "relatedperson", "researcher", "researchgroup", "rightsholder", "supervisor", "sponsor", "workpackageleader", "other"), + allowed_date_types = c("accepted", "available", "collected", "copyrighted", "created", "issued", + "other", "submitted", "updated", "valid", "withdrawn"), allowed_relations = c("isCitedBy", "cites", "isSupplementTo", "isSupplementedBy", "isContinuedBy", "continues", "isDescribedBy", "describes", "hasMetadata", "isMetadataFor", "isNewVersionOf", "isPreviousVersionOf", "isPartOf", "hasPart", "isReferencedBy", "references", "isDocumentedBy", "documents", "isCompiledBy", @@ -295,13 +297,43 @@ ZenodoRecord <- R6Class("ZenodoRecord", self$metadata$publication_date <- publicationDate }, - #' @description Set the embargo date. - #' @param embargoDate object of class \code{Date} - setEmbargoDate = function(embargoDate){ - if(!is(embargoDate,"Date")){ - stop("The embargo date should be a 'Date' object") + #' @description Add date + #' @param date date + #' @param type type of date, among following values: 'accepted', 'available', 'collected', 'copyrighted', + #' 'created', 'issued', 'other', 'submitted', 'updated', 'valid', 'withdrawn' + #' @param description free text, specific information about the date + addDate = function(date, type, description = NULL){ + if(!type %in% private$allowed_date_types){ + errMsg = sprintf("Date type should be among following possible values: %s", + paste0(private$allowed_date_types, collapse=", ")) + self$ERROR(errMsg) + stop(errMsg) } - self$metadata$embargo_date <- as(embargoDate, "character") + if(is.null(self$metadata$dates)) self$metadata$dates = list() + self$metadata$dates[[length(self$metadata$dates)+1]] = list( + date = date, + type = list(id = type), + description = description + ) + }, + + #' @description Remove a date + #' @param date the date to remove + #' @param type the date type of the date to be removed + #' @return \code{TRUE} if removed, \code{FALSE} otherwise + removeDate = function(date, type){ + removed <- FALSE + if(!is.null(self$metadata$dates)){ + for(i in 1:length(self$metadata$dates)){ + dat <- self$metadata$dates[[i]] + if(dat$date == date & dat$type$id == type){ + self$metadata$dates[[i]] <- NULL + removed <- TRUE + break; + } + } + } + return(removed) }, #' @description Set the record title. diff --git a/man/ZenodoRecord.Rd b/man/ZenodoRecord.Rd index 815f851..1ccf0a7 100644 --- a/man/ZenodoRecord.Rd +++ b/man/ZenodoRecord.Rd @@ -90,7 +90,8 @@ Emmanuel Blondel \item \href{#method-ZenodoRecord-setImageType}{\code{ZenodoRecord$setImageType()}} \item \href{#method-ZenodoRecord-setPublisher}{\code{ZenodoRecord$setPublisher()}} \item \href{#method-ZenodoRecord-setPublicationDate}{\code{ZenodoRecord$setPublicationDate()}} -\item \href{#method-ZenodoRecord-setEmbargoDate}{\code{ZenodoRecord$setEmbargoDate()}} +\item \href{#method-ZenodoRecord-addDate}{\code{ZenodoRecord$addDate()}} +\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()}} @@ -462,23 +463,50 @@ please check https://inveniordm.docs.cern.ch/reference/metadata/#publication-dat } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZenodoRecord-setEmbargoDate}{}}} -\subsection{Method \code{setEmbargoDate()}}{ -Set the embargo date. +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-addDate}{}}} +\subsection{Method \code{addDate()}}{ +Add date \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZenodoRecord$setEmbargoDate(embargoDate)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ZenodoRecord$addDate(date, type, description = NULL)}\if{html}{\out{
}} } \subsection{Arguments}{ \if{html}{\out{
}} \describe{ -\item{\code{embargoDate}}{object of class \code{Date}} +\item{\code{date}}{date} + +\item{\code{type}}{type of date, among following values: 'accepted', 'available', 'collected', 'copyrighted', +'created', 'issued', 'other', 'submitted', 'updated', 'valid', 'withdrawn'} + +\item{\code{description}}{free text, specific information about the date} } \if{html}{\out{
}} } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZenodoRecord-removeDate}{}}} +\subsection{Method \code{removeDate()}}{ +Remove a date +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ZenodoRecord$removeDate(date, type)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{date}}{the date to remove} + +\item{\code{type}}{the date type of the date to be removed} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +\code{TRUE} if removed, \code{FALSE} otherwise +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZenodoRecord-setTitle}{}}} \subsection{Method \code{setTitle()}}{