From 2cd381a618e79e8ac155dc97d2bcced0de020f5b Mon Sep 17 00:00:00 2001 From: afwillia Date: Wed, 15 Nov 2023 08:47:15 -0800 Subject: [PATCH 1/8] WIP: add project_scope to validation endpoint --- R/schematic_rest_api.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/schematic_rest_api.R b/R/schematic_rest_api.R index b2e39e0e..31d032e2 100644 --- a/R/schematic_rest_api.R +++ b/R/schematic_rest_api.R @@ -115,12 +115,13 @@ manifest_populate <- function(url="http://localhost:3001/v1/manifest/populate", #' @export manifest_validate <- function(url="http://localhost:3001/v1/model/validate", schema_url="https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld", #nolint - data_type, file_name, restrict_rules=FALSE) { + data_type, file_name, restrict_rules=FALSE, project_scope = NULL) { req <- httr::POST(url, query=list( schema_url=schema_url, data_type=data_type, - restrict_rules=restrict_rules), + restrict_rules=restrict_rules, + project_scope = project_scope), body=list(file_name=httr::upload_file(file_name)) ) From a9f25f0622d75a077236213dd745bc0245097cf5 Mon Sep 17 00:00:00 2001 From: afwillia Date: Wed, 15 Nov 2023 08:49:04 -0800 Subject: [PATCH 2/8] WIP: add asset view as project scope to validation endpoint --- server.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server.R b/server.R index a6a22874..7a60e62d 100644 --- a/server.R +++ b/server.R @@ -727,7 +727,8 @@ shinyServer(function(input, output, session) { .infile_data <- inFile$data() .dd_template <- input$dropdown_template .restrict_rules <- dcc_config_react()$validate_restrict_rules - + .project_scope <- selected$master_asset_view() + promises::future_promise({ annotation_status <- switch(dca_schematic_api, reticulate = manifest_validate_py( @@ -740,7 +741,8 @@ shinyServer(function(input, output, session) { schema_url=.data_model, data_type=.schema, file_name=.datapath, - restrict_rules = .restrict_rules), + restrict_rules = .restrict_rules, + project_scope = .project_scope), { Sys.sleep(0) list(list( From aef9d0b686de011d2cc3164b7a11a397dfc39f44 Mon Sep 17 00:00:00 2001 From: afwillia Date: Tue, 28 Nov 2023 15:55:56 -0800 Subject: [PATCH 3/8] WIP: add ability to pass multiple project_scope to manifest_validate --- R/schematic_rest_api.R | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/R/schematic_rest_api.R b/R/schematic_rest_api.R index c691b822..794c1afa 100644 --- a/R/schematic_rest_api.R +++ b/R/schematic_rest_api.R @@ -115,13 +115,36 @@ manifest_populate <- function(url="http://localhost:3001/v1/manifest/populate", #' @export manifest_validate <- function(url="http://localhost:3001/v1/model/validate", schema_url="https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld", #nolint - data_type, file_name, restrict_rules=FALSE, project_scope = NULL) { + data_type, file_name, restrict_rules=FALSE, project_scope = NULL, + access_token, asset_view = NULL) { + + flattenbody <- function(x) { + # A form/query can only have one value per name, so take + # any values that contain vectors length >1 and + # split them up + # list(x=1:2, y="a") becomes list(x=1, x=2, y="a") + if (all(lengths(x)<=1)) return(x); + do.call("c", mapply(function(name, val) { + if (length(val)==1 || any(c("form_file", "form_data") %in% class(val))) { + x <- list(val) + names(x) <- name + x + } else { + x <- as.list(val) + names(x) <- rep(name, length(val)) + x + } + }, names(x), x, USE.NAMES = FALSE, SIMPLIFY = FALSE)) + } + req <- httr::POST(url, - query=list( + httr::add_headers(Authorization = sprintf("Bearer %s", access_token)), + query=flattenbody(list( schema_url=schema_url, data_type=data_type, restrict_rules=restrict_rules, - project_scope = project_scope), + project_scope = project_scope, + asset_view = asset_view)), body=list(file_name=httr::upload_file(file_name)) ) From e9a4aece5db6c83c08504057645003fba6096731 Mon Sep 17 00:00:00 2001 From: afwillia Date: Tue, 28 Nov 2023 15:56:10 -0800 Subject: [PATCH 4/8] Add asset view to manifest_validate --- server.R | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server.R b/server.R index 644affc1..8e202fb7 100644 --- a/server.R +++ b/server.R @@ -723,9 +723,11 @@ shinyServer(function(input, output, session) { .data_model <- data_model() .infile_data <- inFile$data() .dd_template <- input$dropdown_template - .restrict_rules <- dcc_config_react()$validate_restrict_rules - .project_scope <- selected$master_asset_view() - + .restrict_rules <- dcc_config_react()$schematic$model_validate$restrict_rules + .project_scope <- data_list$projects() + .access_token <- access_token + .asset_view <- selected$master_asset_view() +browser() promises::future_promise({ annotation_status <- switch(dca_schematic_api, reticulate = manifest_validate_py( @@ -739,7 +741,9 @@ shinyServer(function(input, output, session) { data_type=.schema, file_name=.datapath, restrict_rules = .restrict_rules, - project_scope = .project_scope), + project_scope = .project_scope, + access_token = .access_token, + asset_view <- .asset_view), { Sys.sleep(0) list(list( From 4f0e69b7e742ac3d588cbb2d090c8cd044c44f2d Mon Sep 17 00:00:00 2001 From: afwillia Date: Tue, 28 Nov 2023 15:56:10 -0800 Subject: [PATCH 5/8] remove browser statement --- server.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server.R b/server.R index 644affc1..c08c288f 100644 --- a/server.R +++ b/server.R @@ -723,8 +723,10 @@ shinyServer(function(input, output, session) { .data_model <- data_model() .infile_data <- inFile$data() .dd_template <- input$dropdown_template - .restrict_rules <- dcc_config_react()$validate_restrict_rules - .project_scope <- selected$master_asset_view() + .restrict_rules <- dcc_config_react()$schematic$model_validate$restrict_rules + .project_scope <- data_list$projects() + .access_token <- access_token + .asset_view <- selected$master_asset_view() promises::future_promise({ annotation_status <- switch(dca_schematic_api, @@ -739,7 +741,9 @@ shinyServer(function(input, output, session) { data_type=.schema, file_name=.datapath, restrict_rules = .restrict_rules, - project_scope = .project_scope), + project_scope = .project_scope, + access_token = .access_token, + asset_view <- .asset_view), { Sys.sleep(0) list(list( From 1c8626189ce764b9f62c1d22f96f50e2ca1ef38c Mon Sep 17 00:00:00 2001 From: afwillia Date: Thu, 14 Dec 2023 14:50:47 -0800 Subject: [PATCH 6/8] fix argument assignment operator in manifest_validation function call --- server.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.R b/server.R index c08c288f..41d51847 100644 --- a/server.R +++ b/server.R @@ -743,7 +743,7 @@ shinyServer(function(input, output, session) { restrict_rules = .restrict_rules, project_scope = .project_scope, access_token = .access_token, - asset_view <- .asset_view), + asset_view = .asset_view), { Sys.sleep(0) list(list( From 7042e23ac9c01cce46c5ade84737e2a862cea409 Mon Sep 17 00:00:00 2001 From: afwillia Date: Thu, 14 Dec 2023 15:46:09 -0800 Subject: [PATCH 7/8] WIP: check the template config for project scope. If no project scope, set project_scope and asset_view to NULL in manifest_validate to avoid cross-manifest validation --- server.R | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/server.R b/server.R index 41d51847..954189ea 100644 --- a/server.R +++ b/server.R @@ -64,7 +64,8 @@ shinyServer(function(input, output, session) { project = reactiveVal(NULL), folder = reactiveVal(""), schema = reactiveVal(NULL), schema_type = reactiveVal(NULL), master_asset_view = reactiveVal(NULL), - master_asset_view_label = reactiveVal(NULL) + master_asset_view_label = reactiveVal(NULL), + project_scope = reactiveVal(NULL) ) isUpdateFolder <- reactiveVal(FALSE) @@ -540,6 +541,14 @@ shinyServer(function(input, output, session) { selected$schema(data_list$template()[input$dropdown_template]) schema_type <- config_schema()[[1]]$type[which(config_schema()[[1]]$display_name == input$dropdown_template)] selected$schema_type(schema_type) + + # set project scope for each template for cross-manifest validation. + # If project_scope is missing from dca_template_config.json then + # this value will be NULL and cross-manifest validation won't happen. + # validation will occur. + project_scope <- config_schema()[[1]]$project_scope[which(config_schema()[[1]]$display_name == input$dropdown_template)] + selected$project_scope(project_scope) + # clean all tags related with selected template sapply(clean_tags, FUN = hide) }, ignoreInit = TRUE) @@ -724,9 +733,12 @@ shinyServer(function(input, output, session) { .infile_data <- inFile$data() .dd_template <- input$dropdown_template .restrict_rules <- dcc_config_react()$schematic$model_validate$restrict_rules - .project_scope <- data_list$projects() + .project_scope <- selected$project_scope() .access_token <- access_token - .asset_view <- selected$master_asset_view() + # asset view must be NULL to avoid cross-manifest validation. + # doing this in a verbose way to avoid warning with ifelse + .asset_view <- NULL + if (!is.null(.project_scope)) .asset_view <- selected$master_asset_view() promises::future_promise({ annotation_status <- switch(dca_schematic_api, @@ -754,7 +766,7 @@ shinyServer(function(input, output, session) { )) } ) - + # validation messages validationResult(annotation_status, .dd_template, .infile_data) From c397b7a722b302376634996db1a4e8766002a59b Mon Sep 17 00:00:00 2001 From: afwillia Date: Tue, 2 Jan 2024 08:55:15 -0800 Subject: [PATCH 8/8] Remove two obsolete statements. --- server.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/server.R b/server.R index 954189ea..8e3ce26d 100644 --- a/server.R +++ b/server.R @@ -635,7 +635,6 @@ shinyServer(function(input, output, session) { ), { message("Downloading offline manifest") - Sys.sleep(0) tibble(a="b", c="d") } ) @@ -757,7 +756,6 @@ shinyServer(function(input, output, session) { access_token = .access_token, asset_view = .asset_view), { - Sys.sleep(0) list(list( "errors" = list( Row = NA, Column = NA, Value = NA,