Mercurial > repos > ecology > aquainfra_ogc_api_processes
changeset 7:c805cb663bac draft default tip
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/master commit 176da50f4af1ff7f4e0e325984c8edd27fe93926
author | ecology |
---|---|
date | Mon, 21 Jul 2025 06:19:08 +0000 |
parents | 8f9d34c780de |
children | |
files | aquainfra_ogc_api_processes.R aquainfra_ogc_api_processes.xml test-data/points_att_polygon_test_input_1.txt |
diffstat | 3 files changed, 29 insertions(+), 97 deletions(-) [+] |
line wrap: on
line diff
--- a/aquainfra_ogc_api_processes.R Tue May 13 17:57:28 2025 +0000 +++ b/aquainfra_ogc_api_processes.R Mon Jul 21 06:19:08 2025 +0000 @@ -2,7 +2,7 @@ library("jsonlite") library("getopt") -cat("start generic wrapper service \n") +cat("START GENERIC WRAPPER SERVICE \n") remove_null_values <- function(x) { if (is.list(x)) { @@ -33,36 +33,6 @@ return(jsonObject) } -getOutputs <- function(inputs, output, server) { - url <- - paste(paste(server, "processes/", sep = ""), - inputs$select_process, - sep = "") - print(url) - request <- request(url) - response <- req_perform(request) - responseBody <- parseResponseBody(response$body) - outputs <- list() - - for (x in 1:length(responseBody$outputs)) { - outputformatName <- - paste(names(responseBody$outputs[x]), "_outformat", sep = "") - output_item <- list() - - for (p in names(inputs)) { - if (p == outputformatName) { - format <- list("mediaType" = inputs[[outputformatName]]) - output_item$format <- format - } - } - output_item$transmissionMode <- "reference" - outputs[[x]] <- output_item - } - - names(outputs) <- names(responseBody$outputs) - return(outputs) -} - executeProcess <- function(url, process, requestBodyData) { url <- paste(paste(paste(url, "processes/", sep = ""), process, sep = ""), "/execution", sep = "") @@ -77,9 +47,10 @@ req_body_json(body) %>% req_perform() - cat("\n Process executed") - cat("\n status: ", response$status_code) + cat("\n 3.1: Process executed") + cat("\n 3.1: Status code: ", response$status_code) jobId <- parseResponseBody(response$body)$jobID + cat("\n 3.1: Job ID: ", jobId, "\n") return(jobId) } @@ -93,9 +64,7 @@ return(jobStatus) } -getStatusCode <- function(server, process, jobID) { - url <- paste0(server, "jobs/", jobID) - print(url) +getStatusCode <- function(url) { response <- request(url) %>% req_perform() status_code <- response$status_code @@ -125,15 +94,17 @@ } retrieveResults <- function(server, process, jobID, outputData) { - status_code <- getStatusCode(server, process, jobID) - print(status_code) + url <- paste0(server, "jobs/", jobID) + cat(" 4.1: Job URL: ", url) + status_code <- getStatusCode(url) + cat("\n 4.2: Status code: ", status_code, "\n") if (status_code == 200) { status <- "running" while (status == "running") { jobStatus <- checkJobStatus(server, process, jobID) - print(jobStatus) + cat(" 4.3: Job status: ", jobStatus, "\n") if (jobStatus == "successful") { status <- jobStatus @@ -141,27 +112,25 @@ if (result$status_code == 200) { resultBody <- parseResponseBody(result$body) + cat("\n 4.4 Outputs: \n") print(resultBody) hrefs <- findHref(resultBody) if (length(hrefs) > 0) { urls_with_newline <- paste(hrefs, collapse = "\n") - print(urls_with_newline) con <- file(outputData, "w") writeLines(urls_with_newline, con = con) close(con) } else { - print("No hrefs found.") + stop(paste0("Job failed. No hrefs found. See details at: ", server, "jobs/", jobID)) } } } else if (jobStatus == "failed") { - status <- jobStatus + stop(paste0("Job failed. See details at: ", server, "jobs/", jobID)) } Sys.sleep(3) } - cat("\n done \n") - } else if (status_code1 == 400) { print("A query parameter has an invalid value.") } else if (status_code1 == 404) { @@ -185,19 +154,15 @@ server <- "https://aquainfra.ogc.igb-berlin.de/pygeoapi/" -print("--> Retrieve parameters") +cat("\n1: START RETRIEVING PARAMETERS\n\n") inputParameters <- getParameters() -print("--> Parameters retrieved") +print(inputParameters) +cat("1: END RETRIEVING PARAMETERS\n") args <- commandArgs(trailingOnly = TRUE) outputLocation <- args[2] -print("--> Retrieve outputs") -outputs <- getOutputs(inputParameters, outputLocation, server) -print("--> Outputs retrieved") - -print("--> Parse inputs") - +cat("\n2: START PARSING INPUTS\n\n") convertedKeys <- c() for (key in names(inputParameters)) { @@ -209,62 +174,29 @@ con <- file(inputParameters[[key]], "r") lines <- readLines(con) - print(length(lines)) close(con) - json_string <- paste(lines, collapse = "\n") + json_string <- paste(lines, collapse = ",") inputParameters[[key]] <- json_string convertedKeys <- append(convertedKeys, key) - } - else if (grepl("_Array_", key)) { - keyParts <- strsplit(key, split = "_")[[1]] - type <- keyParts[length(keyParts)] - values <- inputParameters[[key]] - value_list <- strsplit(values, split = ",") - convertedValues <- c() - - for (value in value_list) { - if (type == "integer") { - value <- as.integer(value) - } else if (type == "numeric") { - value <- as.numeric(value) - } else if (type == "character") { - value <- as.character(value) - } - convertedValues <- append(convertedValues, value) - - convertedKey <- "" - for (part in keyParts) { - if (part == "Array") { - break - } - convertedKey <- - paste(convertedKey, paste(part, "_", sep = ""), sep = "") - } - convertedKey <- substr(convertedKey, 1, nchar(convertedKey) - 1) - } - - inputParameters[[key]] <- convertedValues - convertedKeys <- append(convertedKeys, convertedKey) } else { if (!is.null(inputParameters[[key]])) { convertedKeys <- append(convertedKeys, key) } } } +names(inputParameters) <- convertedKeys print(inputParameters) -names(inputParameters) <- convertedKeys -print("--> Inputs parsed") - -print("--> Prepare process execution") -jsonData <- list("inputs" = inputParameters, - "outputs" = outputs) +cat("2: END PARSING INPUTSs\n") -print("--> Execute process") +cat("\n3: START EXECUTING PROCESS\n") +jsonData <- list("inputs" = inputParameters) jobId <- executeProcess(server, inputParameters$select_process, jsonData) -print("--> Process executed") +cat("\n3: END EXECUTING PROCESS\n") -print("--> Retrieve results") +cat("\n4: START RETRIEVING RESULTS\n\n") retrieveResults(server, inputParameters$select_process, jobId, outputLocation) -print("--> Results retrieved") \ No newline at end of file +cat("4: END RETRIEVING RESULTS\n") + +cat("\n5: DONE.") \ No newline at end of file
--- a/aquainfra_ogc_api_processes.xml Tue May 13 17:57:28 2025 +0000 +++ b/aquainfra_ogc_api_processes.xml Mon Jul 21 06:19:08 2025 +0000 @@ -1,4 +1,4 @@ -<tool id="aquainfra_ogc_api_processes" name="AquaINFRA OGC API Processes" version="0.6.0" profile="22.05"> +<tool id="aquainfra_ogc_api_processes" name="AquaINFRA OGC API Processes" version="0.6.1" profile="22.05"> <description/> <macros> <import>macros.xml</import>
--- a/test-data/points_att_polygon_test_input_1.txt Tue May 13 17:57:28 2025 +0000 +++ b/test-data/points_att_polygon_test_input_1.txt Mon Jul 21 06:19:08 2025 +0000 @@ -1,1 +1,1 @@ -https://maps.helcom.fi/arcgis/rest/directories/arcgisoutput/MADS/tools_GPServer/_ags_HELCOM_subbasin_with_coastal_WFD_waterbodies_or_wa.zip \ No newline at end of file +https://zenodo.org/records/15234377/files/inputdata_shapefile.zip?download=1 \ No newline at end of file