Skip to content

Commit

Permalink
Merge pull request #124 from kalili99/main
Browse files Browse the repository at this point in the history
 modified html script and added endpoints for code and file
  • Loading branch information
dgarijo authored Nov 6, 2024
2 parents fb8ae93 + 2195000 commit 6b6b09a
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 39 deletions.
140 changes: 101 additions & 39 deletions html_client/FAIR_validator.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,99 @@
<!-- Javascript -->
<script src="./FAIR_validator.js"></script>
<script>
$(document).ready(function(){
$('#loader').hide();
$('#run_button').click(function(){
$('#loader').show();
$('#run_button').hide();

if ($('#URI_input').val() != ""){
// console.log('the value is not null');
$.ajax({
url:"https://foops.linkeddata.es/assessOntology",
type:"POST",
data:"{ \"ontologyUri\": \""+$('#URI_input').val()+"\"}",
contentType:"application/json; charset=utf-8",
success: function(data, status){
$('#loader').hide();
$('#run_button').show();
run(data)
}
}).fail(function (jqXHR, textStatus, error) {
$('#loader').hide();
$('#run_button').show();
alert('Error when contacting the server!' );
});
}
else{
$('#loader').hide();
$('#run_button').show();
alert('Please enter an URI!' );
}
});
});
$(document).ready(function(){
$('#loader').hide();
$('#run_button').click(function(){
$('#loader').show();
$('#run_button').hide();
const MAX_FILE_SIZE = 20 * 1024 * 1024; // 20MB en bytes
if ($('#URI_input').val() != ""){
// console.log('the value is not null');
$.ajax({
// url:"https://foops.linkeddata.es/assessOntology",
url:"http://localhost:8080/assessOntology",
type:"POST",
data:"{ \"ontologyUri\": \""+$('#URI_input').val()+"\"}",
contentType:"application/json; charset=utf-8",
success: function(data, status){
$('#loader').hide();
$('#run_button').show();
run(data)
}
}).fail(function (jqXHR, textStatus, error) {
$('#loader').hide();
$('#run_button').show();
alert('Error when contacting the server!' );
});
}

else if ($('#File_input').val() != ""){
console.log('the file is not null');
var fileInput = $('#File_input')[0];
var file = fileInput.files[0];
if(!file){
alert('The file is not selected');
return;
}
if (file.size > MAX_FILE_SIZE) {
alert('The file is too big');
return;
}
var formData = new FormData();
formData.append('file', file);
$.ajax({
url: "http://localhost:8080/assessOntologyFile",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function(data, status){
$('#loader').hide();
$('#run_button').show();
run(data);
}
}).fail(function (jqXHR, textStatus, error) {
$('#loader').hide();
$('#run_button').show();
alert('Error when contacting the server!');
});
}
else if ($('#Code_input').val() != ""){
var formData2 = new FormData();
var ontologyCode = document.getElementById('Code_input').value;
var blob = new Blob([ontologyCode], { type: 'text/plain' });
var file = new File([blob], "ontology.owl", { type: "text/plain" });
if (file.size > MAX_FILE_SIZE) {
alert('Too much text');
return;
}

formData2.append('file', file);
$.ajax({
url: "http://localhost:8080/assessOntologyFile",
type: "POST",
data: formData2,
processData: false,
contentType: false,
success: function(data, status){
$('#loader').hide();
$('#run_button').show();
run(data);
}
}).fail(function (jqXHR, textStatus, error) {
$('#loader').hide();
$('#run_button').show();
alert('Error when contacting the server!');
});

}
else{
$('#loader').hide();
$('#run_button').show();
alert('Please enter an URI!' );
}
});
});
</script>

<title>FOOPS!</title>
Expand Down Expand Up @@ -121,14 +183,14 @@
<div class="col-4 selector selector-izq center active" onclick="openInput(event, 'URI')">
<span class="texto3"> URI </span>
</div>
<!-- Codigo
<!-- Codigo-->
<div class="col-4 selector center" onclick="openInput(event, 'Code')">
<span class="texto3"> Code </span>
</div>-->
<!-- Archivo
</div>
<!-- Archivo-->
<div class="col-4 selector selector-der center" onclick="openInput(event, 'File')">
<span class="texto3"> File </span>
</div>-->
</div>
</div>

<!-- Input de URI-->
Expand All @@ -144,20 +206,20 @@
</p>
</div>
</div>
<!-- Input del código (commented until implemented)
<!-- Input del código -->
<div id="Code" class="row selector-content mt-3" style="display: none">
<div class="col-12 center">
<textarea id="Code_input" class="input-2" placeholder="Paste here your ontology code. Please note that if you enter the ontology URI instead of the code there are more checks that we can do for you. For example, to test whether Content Negotiation is used for serving the ontology."></textarea>
</div>
</div>
-->
<!-- Input del archivo (commented until implemented)

<!-- Input del archivo -->
<div id="File" class="row selector-content mt-3" style="display: none">
<div class="col-12">
<input id="File_input" class="input-1" type="file" placeholder="Drag and drop the file to upload here">
</div>
</div>
-->

</div>
</div>
</div>
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/server/FOOPSController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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\"}";
}

}
}

0 comments on commit 6b6b09a

Please sign in to comment.