Skip to content

Commit

Permalink
importZipStudyWeb with new parameters delete_zipfile and folder_desti…
Browse files Browse the repository at this point in the history
…nation (#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
  • Loading branch information
KKamel67 authored Jul 5, 2024
1 parent 14259d9 commit 8edae19
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/createClusterST.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/createStudy.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 18 additions & 6 deletions R/importStudyAPI.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand All @@ -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))
}
2 changes: 1 addition & 1 deletion man/create-study.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/createClusterST.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion man/importZipStudyWeb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8edae19

Please sign in to comment.