From 21950002de50c8660e0dbb253c56df8836d00105 Mon Sep 17 00:00:00 2001 From: Kalili Date: Mon, 4 Nov 2024 16:32:16 +0100 Subject: [PATCH] Added fileInput and codeInput --- html_client/FAIR_validator.html | 140 ++++++++++++++++------ src/main/java/server/FOOPSController.java | 51 ++++++++ 2 files changed, 152 insertions(+), 39 deletions(-) diff --git a/html_client/FAIR_validator.html b/html_client/FAIR_validator.html index 41249c9..ce11760 100644 --- a/html_client/FAIR_validator.html +++ b/html_client/FAIR_validator.html @@ -31,37 +31,99 @@ FOOPS! @@ -121,14 +183,14 @@
URI
-
Code -
--> -
File -
--> + @@ -144,20 +206,20 @@

- - --> - - --> + diff --git a/src/main/java/server/FOOPSController.java b/src/main/java/server/FOOPSController.java index 6f65d7a..e151f67 100644 --- a/src/main/java/server/FOOPSController.java +++ b/src/main/java/server/FOOPSController.java @@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.server.ResponseStatusException; import java.io.File; @@ -107,4 +108,54 @@ public String assessPOST(@RequestBody String body) { HttpStatus.BAD_REQUEST, "Error while processing the request", e); } } + + /** + * + * @param file Archivo enviado como parte del FormData. + * @param otherData String opcional con otros datos enviados. + * @return Respuesta JSON obtenida por FOOPS. + */ + @CrossOrigin(origins = "*") + @PostMapping(path = "/assessOntologyFile",consumes = "multipart/form-data", produces = "application/json") + public String assessPOSTe( + @RequestParam("file") MultipartFile file, + @RequestParam(value = "otherData", required = false) String otherData) { + FOOPS f = null; + String fileContent = null; + if (!file.isEmpty()) { + String fileName = file.getOriginalFilename(); + System.out.println("file Name: " + fileName); + + + try { + fileContent = new String(file.getBytes()); + try{ + if (f == null && fileContent!=null){ + f = new FOOPS(fileName, true); + } + if (f == null){ + throw new ResponseStatusException( + HttpStatus.BAD_REQUEST, "Could not load ontology", new Exception("Ontology URI or ontology content not provided")); + } + f.fairTest(); + return f.exportJSON(); + + }catch(ResponseStatusException e) { + throw e; + } } catch (Exception e) { + e.printStackTrace(); + return "{\"error\":\"Error processing file\"}"; + } + finally{ + if (f != null){ + f.removeTemporaryFolders(); + } + + } + } + else { + return "{\"error\":\"No file detected\"}"; + } + + } } \ No newline at end of file