Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fds 2200 validation error #610

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion R/schematic_rest_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,14 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
# )
# )
# }
httr2::resp_body_json(resp)
if (httr2::resp_is_error(resp)) {
list(list(
"errors" = list(
Row = NA, Column = NA, Value = NA,
Error = httr2::resp_body_string(resp)
)
))
} else httr2::resp_body_json(resp)
}


Expand Down
14 changes: 14 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,18 @@ parse_env_var <- function(x, el_delim=",", kv_delim=":"){
kv <- stringr::str_split(y, kv_delim, n=2)
setNames(kv[[1]][[2]], kv[[1]][[1]])
}))
}

#' @title Truncate the results of schematic validation
#' @param x Schematic validation result
#' @param n Number of records to keep
#' @export
format_validation_response <- function(x, n = 50) {
if ("errors" %in% names(x) && length(x$errors) > n) {
x$errors <- x$errors[1:n]
}
if ("warnings" %in% names(x) && length(x$warnings) > n) {
x$warnings <- x$warnings[1:n]
}
x
}
36 changes: 30 additions & 6 deletions functions/schematic_rest_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ check_success <- function(x){
if (tolower(status$category) == "success") {
return()
} else {
# Return content text for Data Type errors
if (grepl("LookupError: The DataType", httr::content(x, "text"))) {
stop(httr::content(x, "text"))
}

stop(sprintf("Response from server: %s", status$reason))
}
}
Expand Down Expand Up @@ -211,7 +216,14 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
# )
# )
# }
httr2::resp_body_json(resp)
if (httr2::resp_is_error(resp)) {
list(list(
"errors" = list(
Row = NA, Column = NA, Value = NA,
Error = httr2::resp_body_string(resp)
)
))
} else httr2::resp_body_json(resp)
}


Expand All @@ -221,8 +233,18 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
#' @param schema_url URL to a schema jsonld
#' @param data_type Type of dataset
#' @param dataset_id Synapse ID of existing manifest
#' @param access_token Synapse login cookie, PAT, or API key.
#' @param csv_file Filepath of csv to validate
#' @param restrict_rules Default = FALSE
#' @param access_token Synapse login cookie, PAT, or API key
#' @param json_str Json string to submit
#' @param asset_view Synapse fileview
#' @param manifest_record_type Default = "table_and_file"
#' @param file_name Name of file
#' @param table_manipulation Default = "replace"
#' @param hide_blanks Default = FALSE
#' @param table_column_names Default = "class_and_label"
#' @param annotation_keys Default = "class_and_label"
#' @param data_model_labels Default = "class_and_label"
#' @param upload_file_annotations Default = TRUE
#'
#' @returns TRUE if successful upload or validate errors if not.
#' @export
Expand All @@ -240,7 +262,8 @@ model_submit <- function(url="http://localhost:3001/v1/model/submit",
hide_blanks=FALSE,
table_column_names="class_label",
annotation_keys="class_label",
data_model_labels="class_label") {
data_model_labels="class_label",
file_annotations_upload=TRUE) {
req <- httr::POST(url,
httr::add_headers(Authorization = sprintf("Bearer %s", access_token)),
query=list(
Expand All @@ -255,7 +278,8 @@ model_submit <- function(url="http://localhost:3001/v1/model/submit",
table_column_names=table_column_names,
annotation_keys=annotation_keys,
data_model_labels=data_model_labels,
hide_blanks=hide_blanks),
hide_blanks=hide_blanks,
file_annotations_upload=file_annotations_upload),
body=list(file_name=httr::upload_file(file_name))
#body=list(file_name=file_name)
)
Expand Down Expand Up @@ -397,7 +421,7 @@ get_asset_view_table <- function(url="http://localhost:3001/v1/storage/assets/ta

check_success(req)
if (return_type=="json") {
return(list2DF(fromJSON(httr::content(req))))
return(list2DF(jsonlite::fromJSON(httr::content(req))))
} else {
csv <- readr::read_csv(httr::content(req), show_col_types = FALSE)
return(csv)
Expand Down
3 changes: 2 additions & 1 deletion server.R
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ shinyServer(function(input, output, session) {
)

# validation messages
annotation_status <- format_validation_response(annotation_status, 50)
validationResult(annotation_status, .dd_template, .infile_data)
}) %...>% validation_res()
})
Expand Down Expand Up @@ -1067,7 +1068,7 @@ shinyServer(function(input, output, session) {
.restrict_rules <- dcc_config_react()$schematic$model_validate$restrict_rules
.hide_blanks <- dcc_config_react()$schematic$model_submit$hide_blanks
.file_annotations_upload <- dcc_config_react()$schematic$model_submit$file_annotations_upload

# associates metadata with data and returns manifest id
promises::future_promise({
try(
Expand Down
Loading