Skip to content

Commit

Permalink
Merge pull request #581 from Sage-Bionetworks/FDS-1301-cross-manifest…
Browse files Browse the repository at this point in the history
…-validation

Fds 1301 cross manifest validation
  • Loading branch information
afwillia authored Jan 2, 2024
2 parents ae3c103 + c5d066c commit a5532ba
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
30 changes: 27 additions & 3 deletions R/schematic_rest_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +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) {
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),
restrict_rules=restrict_rules,
project_scope = project_scope,
asset_view = asset_view)),
body=list(file_name=httr::upload_file(file_name))
)

Expand Down
28 changes: 22 additions & 6 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -626,7 +635,6 @@ shinyServer(function(input, output, session) {
),
{
message("Downloading offline manifest")
Sys.sleep(0)
tibble(a="b", c="d")
}
)
Expand Down Expand Up @@ -724,7 +732,13 @@ 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 <- selected$project_scope()
.access_token <- access_token
# 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,
reticulate = manifest_validate_py(
Expand All @@ -737,9 +751,11 @@ 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,
access_token = .access_token,
asset_view = .asset_view),
{
Sys.sleep(0)
list(list(
"errors" = list(
Row = NA, Column = NA, Value = NA,
Expand All @@ -748,7 +764,7 @@ shinyServer(function(input, output, session) {
))
}
)

# validation messages
validationResult(annotation_status, .dd_template, .infile_data)

Expand Down

0 comments on commit a5532ba

Please sign in to comment.