Skip to content

Commit a5532ba

Browse files
authored
Merge pull request #581 from Sage-Bionetworks/FDS-1301-cross-manifest-validation
Fds 1301 cross manifest validation
2 parents ae3c103 + c5d066c commit a5532ba

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

R/schematic_rest_api.R

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,36 @@ manifest_populate <- function(url="http://localhost:3001/v1/manifest/populate",
115115
#' @export
116116
manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
117117
schema_url="https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld", #nolint
118-
data_type, file_name, restrict_rules=FALSE) {
118+
data_type, file_name, restrict_rules=FALSE, project_scope = NULL,
119+
access_token, asset_view = NULL) {
120+
121+
flattenbody <- function(x) {
122+
# A form/query can only have one value per name, so take
123+
# any values that contain vectors length >1 and
124+
# split them up
125+
# list(x=1:2, y="a") becomes list(x=1, x=2, y="a")
126+
if (all(lengths(x)<=1)) return(x);
127+
do.call("c", mapply(function(name, val) {
128+
if (length(val)==1 || any(c("form_file", "form_data") %in% class(val))) {
129+
x <- list(val)
130+
names(x) <- name
131+
x
132+
} else {
133+
x <- as.list(val)
134+
names(x) <- rep(name, length(val))
135+
x
136+
}
137+
}, names(x), x, USE.NAMES = FALSE, SIMPLIFY = FALSE))
138+
}
139+
119140
req <- httr::POST(url,
120-
query=list(
141+
httr::add_headers(Authorization = sprintf("Bearer %s", access_token)),
142+
query=flattenbody(list(
121143
schema_url=schema_url,
122144
data_type=data_type,
123-
restrict_rules=restrict_rules),
145+
restrict_rules=restrict_rules,
146+
project_scope = project_scope,
147+
asset_view = asset_view)),
124148
body=list(file_name=httr::upload_file(file_name))
125149
)
126150

server.R

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ shinyServer(function(input, output, session) {
6464
project = reactiveVal(NULL), folder = reactiveVal(""),
6565
schema = reactiveVal(NULL), schema_type = reactiveVal(NULL),
6666
master_asset_view = reactiveVal(NULL),
67-
master_asset_view_label = reactiveVal(NULL)
67+
master_asset_view_label = reactiveVal(NULL),
68+
project_scope = reactiveVal(NULL)
6869
)
6970

7071
isUpdateFolder <- reactiveVal(FALSE)
@@ -540,6 +541,14 @@ shinyServer(function(input, output, session) {
540541
selected$schema(data_list$template()[input$dropdown_template])
541542
schema_type <- config_schema()[[1]]$type[which(config_schema()[[1]]$display_name == input$dropdown_template)]
542543
selected$schema_type(schema_type)
544+
545+
# set project scope for each template for cross-manifest validation.
546+
# If project_scope is missing from dca_template_config.json then
547+
# this value will be NULL and cross-manifest validation won't happen.
548+
# validation will occur.
549+
project_scope <- config_schema()[[1]]$project_scope[which(config_schema()[[1]]$display_name == input$dropdown_template)]
550+
selected$project_scope(project_scope)
551+
543552
# clean all tags related with selected template
544553
sapply(clean_tags, FUN = hide)
545554
}, ignoreInit = TRUE)
@@ -626,7 +635,6 @@ shinyServer(function(input, output, session) {
626635
),
627636
{
628637
message("Downloading offline manifest")
629-
Sys.sleep(0)
630638
tibble(a="b", c="d")
631639
}
632640
)
@@ -724,7 +732,13 @@ shinyServer(function(input, output, session) {
724732
.infile_data <- inFile$data()
725733
.dd_template <- input$dropdown_template
726734
.restrict_rules <- dcc_config_react()$schematic$model_validate$restrict_rules
727-
735+
.project_scope <- selected$project_scope()
736+
.access_token <- access_token
737+
# asset view must be NULL to avoid cross-manifest validation.
738+
# doing this in a verbose way to avoid warning with ifelse
739+
.asset_view <- NULL
740+
if (!is.null(.project_scope)) .asset_view <- selected$master_asset_view()
741+
728742
promises::future_promise({
729743
annotation_status <- switch(dca_schematic_api,
730744
reticulate = manifest_validate_py(
@@ -737,9 +751,11 @@ shinyServer(function(input, output, session) {
737751
schema_url=.data_model,
738752
data_type=.schema,
739753
file_name=.datapath,
740-
restrict_rules = .restrict_rules),
754+
restrict_rules = .restrict_rules,
755+
project_scope = .project_scope,
756+
access_token = .access_token,
757+
asset_view = .asset_view),
741758
{
742-
Sys.sleep(0)
743759
list(list(
744760
"errors" = list(
745761
Row = NA, Column = NA, Value = NA,
@@ -748,7 +764,7 @@ shinyServer(function(input, output, session) {
748764
))
749765
}
750766
)
751-
767+
752768
# validation messages
753769
validationResult(annotation_status, .dd_template, .infile_data)
754770

0 commit comments

Comments
 (0)