From 186b9e3bf20d53413c7ecc71a080db43960deeb9 Mon Sep 17 00:00:00 2001 From: afwillia Date: Wed, 30 Oct 2024 14:45:54 -0700 Subject: [PATCH 1/3] import httr2 --- global.R | 1 + 1 file changed, 1 insertion(+) diff --git a/global.R b/global.R index 62fa4e01..c7368d96 100644 --- a/global.R +++ b/global.R @@ -18,6 +18,7 @@ suppressPackageStartupMessages({ library(shinydashboardPlus) library(promises) library(future) + library(httr2) # dashboard library(purrr) library(data.table) From d0e214bdfb2cb7d60f9d4238bf3534f183647fe0 Mon Sep 17 00:00:00 2001 From: afwillia Date: Wed, 30 Oct 2024 14:48:42 -0700 Subject: [PATCH 2/3] Add data model version to manifest and annotations. If data_model_version_as_column = TRUE, as data model URL as a column to the manifest. If data_model_version_as_annotation = TRUE, add data model URL as an annotation to the manifest and folder. --- server.R | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/server.R b/server.R index f624d983..b0103904 100644 --- a/server.R +++ b/server.R @@ -959,6 +959,10 @@ shinyServer(function(input, output, session) { # reads file csv again submit_data <- csvInfileServer("inputFile", colsAsCharacters = TRUE, keepBlank = TRUE, trimEmptyRows = TRUE)$data() + # If enabled, create a column in the manifest to store the data model URL + if (isTRUE(dcc_config_react()$dcc$data_model_version_as_column)) { + submit_data$DataModelURL <- data_model() + } # If a file-based component selected (define file-based components) note for future # the type to filter (eg file-based) on could probably also be a config choice display_names <- config_schema()$manifest_schemas$display_name[config_schema()$manifest_schemas$type == "file"] @@ -1132,6 +1136,38 @@ shinyServer(function(input, output, session) { # if no error if (startsWith(manifest_id(), "syn") == TRUE) { + # If enabled, annotate the file and folder with the data model + if (isTRUE(dcc_config_react()$dcc$data_model_version_as_annotation)) { + lapply(c(manifest_id(), selected$folder()), function(id) { + # Get existing annotations + annotations <- request(sprintf("https://repo-prod.prod.sagebase.org/repo/v1/entity/%s/annotations2", id)) |> + req_auth_bearer_token(access_token) |> + req_perform() |> + resp_body_json() + annotations_upload <- annotations$annotations + if (!"DataModelURL" %in% names(annotations_upload)) { + annotations_upload$DataModelURL <- list( + type="STRING", value=list(data_model()) + ) + } + add_annotation <- request( + sprintf( + "https://repo-prod.prod.sagebase.org/repo/v1/entity/%s/annotations2", + id + )) |> + req_method("PUT") |> + req_auth_bearer_token(access_token) |> + req_body_json( + list( + id = id, + etag = annotations$etag, + annotations = annotations_upload + ) + ) |> + req_error(is_error = function(x) FALSE) |> + req_perform() + }) + } dcWaiter("hide") nx_report_success("Success!", HTML(paste0("Manifest submitted to: ", manifest_path))) From c5f17312ddef7244c72c5f867cdd2ca8abc9ef38 Mon Sep 17 00:00:00 2001 From: afwillia Date: Thu, 31 Oct 2024 09:58:58 -0700 Subject: [PATCH 3/3] only annotate the manifest, not folder --- server.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.R b/server.R index b0103904..962ecce0 100644 --- a/server.R +++ b/server.R @@ -1138,7 +1138,7 @@ shinyServer(function(input, output, session) { if (startsWith(manifest_id(), "syn") == TRUE) { # If enabled, annotate the file and folder with the data model if (isTRUE(dcc_config_react()$dcc$data_model_version_as_annotation)) { - lapply(c(manifest_id(), selected$folder()), function(id) { + lapply(c(manifest_id()), function(id) { # add selected$folder() if annotating folder. # Get existing annotations annotations <- request(sprintf("https://repo-prod.prod.sagebase.org/repo/v1/entity/%s/annotations2", id)) |> req_auth_bearer_token(access_token) |>