Mercurial > repos > ecology > aquainfra_ogc_api_processes
comparison aquainfra_ogc_api_processes.R @ 8:71f754d61a04 draft
planemo upload for repository https://github.com/AquaINFRA/tools-ecology/tree/master commit d6d779f958b5d3347769bdc83c885950ae975a42
| author | ecology |
|---|---|
| date | Fri, 15 Aug 2025 11:19:31 +0000 |
| parents | 78768c06b60f |
| children |
comparison
equal
deleted
inserted
replaced
| 7:78768c06b60f | 8:71f754d61a04 |
|---|---|
| 164 | 164 |
| 165 cat("\n2: START PARSING INPUTS\n\n") | 165 cat("\n2: START PARSING INPUTS\n\n") |
| 166 convertedKeys <- c() | 166 convertedKeys <- c() |
| 167 | 167 |
| 168 for (key in names(inputParameters)) { | 168 for (key in names(inputParameters)) { |
| 169 value_no_spaces <- gsub(" ", "", inputParameters[[key]]) | |
| 170 if (value_no_spaces == "") { | |
| 171 inputParameters[[key]] <- NULL | |
| 172 } | |
| 173 | |
| 169 if (is.character(inputParameters[[key]]) && | 174 if (is.character(inputParameters[[key]]) && |
| 170 (endsWith(inputParameters[[key]], ".dat") || | 175 (endsWith(inputParameters[[key]], ".dat") || |
| 171 endsWith(inputParameters[[key]], ".txt"))) { | 176 endsWith(inputParameters[[key]], ".txt"))) { |
| 172 con <- file(inputParameters[[key]], "r") | 177 con <- file(inputParameters[[key]], "r") |
| 173 url_list <- list() | 178 url_list <- list() |
| 178 | 183 |
| 179 json_string <- paste(lines, collapse = ",") | 184 json_string <- paste(lines, collapse = ",") |
| 180 inputParameters[[key]] <- json_string | 185 inputParameters[[key]] <- json_string |
| 181 | 186 |
| 182 convertedKeys <- append(convertedKeys, key) | 187 convertedKeys <- append(convertedKeys, key) |
| 183 } else { | 188 } else if ( |
| 189 grepl("_object", key) && | |
| 190 !is.null(inputParameters[[key]]) && | |
| 191 !is.na(inputParameters[[key]]) && | |
| 192 gsub(" ", "", inputParameters[[key]]) != "" | |
| 193 ) { | |
| 194 decoded_value <- gsub("__oc__", "{", inputParameters[[key]]) | |
| 195 decoded_value <- gsub("__cc__", "}", decoded_value) | |
| 196 decoded_value <- gsub("__ob__", "[", decoded_value) | |
| 197 decoded_value <- gsub("__cb__", "]", decoded_value) | |
| 198 decoded_value <- gsub("__dq__", "\"", decoded_value) # Optional: sometimes used for quotes | |
| 199 decoded_value <- gsub("__cn__", ":", decoded_value) # Optional: used for colon in older versions | |
| 200 | |
| 201 parsed_json <- fromJSON(decoded_value) | |
| 202 convertedKey <- gsub("_object", "", key) | |
| 203 convertedKeys <- append(convertedKeys, convertedKey) | |
| 204 #json_string <- toJSON(parsed_json, auto_unbox = FALSE) | |
| 205 inputParameters[[key]] <- parsed_json | |
| 206 } else if (grepl("_array", key)) { | |
| 207 keyParts <- strsplit(key, split = "_")[[1]] | |
| 208 type <- keyParts[length(keyParts)] | |
| 209 values <- inputParameters[[key]] | |
| 210 if (is.character(values) && grepl(",", values)) { | |
| 211 value_list <- unlist(strsplit(values, split = ",")) | |
| 212 } else if (is.character(values)) { | |
| 213 value_list <- c(values) | |
| 214 } | |
| 215 | |
| 216 convertedValues <- c() | |
| 217 | |
| 218 for (value in value_list) { | |
| 219 value <- as.character(value) | |
| 220 value <- gsub(" ", "", value) | |
| 221 #if(type == "integer") { | |
| 222 # value <- as.integer(value) | |
| 223 #} else if (type == "numeric") { | |
| 224 # value <- as.numeric(balue) | |
| 225 #} else if (type == "character") { | |
| 226 # value <- as.character(value) | |
| 227 # value <- gsub(" ", "", value) | |
| 228 #} | |
| 229 convertedValues <- append(convertedValues, value) | |
| 230 convertedKey <- "" | |
| 231 for (part in keyParts) { | |
| 232 if(part == "array") { | |
| 233 break | |
| 234 } | |
| 235 convertedKey <- paste(convertedKey, paste(part, "_", sep=""), sep="") | |
| 236 } | |
| 237 convertedKey <- substr(convertedKey, 1, nchar(convertedKey)-1) | |
| 238 } | |
| 239 inputParameters[[key]] <- convertedValues | |
| 240 convertedKeys <- append(convertedKeys, convertedKey) | |
| 241 } | |
| 242 else { | |
| 184 if (!is.null(inputParameters[[key]])) { | 243 if (!is.null(inputParameters[[key]])) { |
| 185 convertedKeys <- append(convertedKeys, key) | 244 convertedKeys <- append(convertedKeys, key) |
| 186 } | 245 } |
| 187 } | 246 } |
| 188 } | 247 } |
