From 8edae19abbb687b8c294fc2e8557d2086d39e314 Mon Sep 17 00:00:00 2001 From: KKamel67 <58913912+KKamel67@users.noreply.github.com> Date: Fri, 5 Jul 2024 09:31:35 +0200 Subject: [PATCH] importZipStudyWeb with new parameters delete_zipfile and folder_destination (#174) * Add folder_destination and delete_zipfile arguments to importZipStudyWeb * Fix CI/CD alert : provide package anchors for all Rd \link{} targets not in the package itself and the base packages. * Update .Rd file after package check --- NEWS.md | 1 + R/createClusterST.R | 2 +- R/createStudy.R | 2 +- R/importStudyAPI.R | 24 ++++++++++++++++++------ man/create-study.Rd | 2 +- man/createClusterST.Rd | 2 +- man/importZipStudyWeb.Rd | 13 ++++++++++++- 7 files changed, 35 insertions(+), 11 deletions(-) diff --git a/NEWS.md b/NEWS.md index e1ff766a..ad1758f2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ * `createBindingConstraint()` / `editBindingConstraint()` uses metadata to check the group size of time series. * `createBindingConstraintBulk()` checks consistency of groups passed as parameters and consistency with the study. +* `importZipStudyWeb()` can delete the zipfile and move the study in Antares Web to another folder * delete `antaresRead-reexports.R` and adjust scripts to have a clean package * `removeArea()` : send a warning instead of a stop if an area is referenced in a binding constraint coefficient * `removeLink()` : send a warning instead of a stop if a link is referenced in a binding constraint coefficient diff --git a/R/createClusterST.R b/R/createClusterST.R index 114ac949..e6bebf07 100644 --- a/R/createClusterST.R +++ b/R/createClusterST.R @@ -30,7 +30,7 @@ #' - lower-rule-curve.txt #' - upper-rule-curve.txt #' -#' @seealso [editClusterST()] to edit existing clusters, [readClusterSTDesc()] to read cluster, +#' @seealso [editClusterST()] to edit existing clusters, [antaresRead::readClusterSTDesc()] to read cluster, #' [removeClusterST()] to remove clusters. #' #' @export diff --git a/R/createStudy.R b/R/createStudy.R index 74a86a0f..376e0a80 100644 --- a/R/createStudy.R +++ b/R/createStudy.R @@ -8,7 +8,7 @@ #' @param study_name Name of the study. #' @param antares_version Antares number version. #' -#' @return Result of [antaresRead::setSimulationPath()] or [setSimulationPathAPI()] accordingly. +#' @return Result of [antaresRead::setSimulationPath()] or [antaresRead::setSimulationPathAPI()] accordingly. #' @export #' #' @name create-study diff --git a/R/importStudyAPI.R b/R/importStudyAPI.R index 840aadf9..0b8ca74a 100644 --- a/R/importStudyAPI.R +++ b/R/importStudyAPI.R @@ -54,6 +54,8 @@ copyStudyWeb <- function(opts = antaresRead::simOptions(), host, token, #' @param host Host of AntaREST server API. #' @param token API personnal access token. #' @param zipfile_name Name of the zipfile of the study. +#' @param delete_zipfile Should the zipfile be deleted after upload. +#' @param folder_destination Folder of the study in Antares Web. #' #' @template opts #' @@ -62,26 +64,36 @@ copyStudyWeb <- function(opts = antaresRead::simOptions(), host, token, #' #' @export #' -importZipStudyWeb <- function(host, token, zipfile_name, opts = antaresRead::simOptions()) { +importZipStudyWeb <- function(host, token, zipfile_name, delete_zipfile = TRUE, folder_destination = NULL, opts = antaresRead::simOptions()) { - # Build the destination folder - dir_study <- unlist(strsplit(opts$studyPath, split = .Platform$file.sep)) - dir_study <- dir_study[seq(length(dir_study) - 1)] - dir_study <- do.call("file.path", as.list(dir_study)) + # Dstination folder + dir_study <- dirname(opts$studyPath) # Zip the study zipfile <- backupStudy(zipfile_name, what = "study", opts = opts, extension = ".zip") + zipfile_path <- file.path(dir_study, zipfile) # Import the study studyId <- api_post( opts = list(host = host, token = token), endpoint = "_import", default_endpoint = "v1/studies", - body = list(study = upload_file(file.path(dir_study, zipfile))), + body = list(study = upload_file(zipfile_path)), encode = "multipart" ) opts <- setSimulationPathAPI(host = host, token = token, study_id = studyId, simulation = "input") + # Move the study + if (!is.null(folder_destination)) { + api_put(opts = opts, + endpoint = file.path(paste0(opts$study_id, "/move?folder_dest=", folder_destination)), + default_endpoint = "v1/studies" + ) + } + + if (delete_zipfile) { + file.remove(zipfile_path) + } return(invisible(opts)) } \ No newline at end of file diff --git a/man/create-study.Rd b/man/create-study.Rd index 2bfa540c..a274b962 100644 --- a/man/create-study.Rd +++ b/man/create-study.Rd @@ -31,7 +31,7 @@ if it doesn't exist, it'll be created.} \item{...}{Other query parameters passed to POST request.} } \value{ -Result of \code{\link[antaresRead:setSimulationPath]{antaresRead::setSimulationPath()}} or \code{\link[=setSimulationPathAPI]{setSimulationPathAPI()}} accordingly. +Result of \code{\link[antaresRead:setSimulationPath]{antaresRead::setSimulationPath()}} or \code{\link[antaresRead:setSimulationPath]{antaresRead::setSimulationPathAPI()}} accordingly. } \description{ Create study on disk or with AntaREST server through the API. diff --git a/man/createClusterST.Rd b/man/createClusterST.Rd index b50ea632..d3e8b526 100644 --- a/man/createClusterST.Rd +++ b/man/createClusterST.Rd @@ -103,6 +103,6 @@ createClusterST(area = "my_area", } \seealso{ -\code{\link[=editClusterST]{editClusterST()}} to edit existing clusters, \code{\link[=readClusterSTDesc]{readClusterSTDesc()}} to read cluster, +\code{\link[=editClusterST]{editClusterST()}} to edit existing clusters, \code{\link[antaresRead:readClusterDesc]{antaresRead::readClusterSTDesc()}} to read cluster, \code{\link[=removeClusterST]{removeClusterST()}} to remove clusters. } diff --git a/man/importZipStudyWeb.Rd b/man/importZipStudyWeb.Rd index 8bdb7eec..2ceb834e 100644 --- a/man/importZipStudyWeb.Rd +++ b/man/importZipStudyWeb.Rd @@ -4,7 +4,14 @@ \alias{importZipStudyWeb} \title{Import a local study to Antares Web} \usage{ -importZipStudyWeb(host, token, zipfile_name, opts = antaresRead::simOptions()) +importZipStudyWeb( + host, + token, + zipfile_name, + delete_zipfile = TRUE, + folder_destination = NULL, + opts = antaresRead::simOptions() +) } \arguments{ \item{host}{Host of AntaREST server API.} @@ -13,6 +20,10 @@ importZipStudyWeb(host, token, zipfile_name, opts = antaresRead::simOptions()) \item{zipfile_name}{Name of the zipfile of the study.} +\item{delete_zipfile}{Should the zipfile be deleted after upload.} + +\item{folder_destination}{Folder of the study in Antares Web.} + \item{opts}{List of simulation parameters returned by the function \code{\link[antaresRead:setSimulationPath]{antaresRead::setSimulationPath()}}} }