Skip to content

Commit

Permalink
Merge pull request #454 from dice-group/dev/arjanoop/446_file_upload_…
Browse files Browse the repository at this point in the history
…failure_handling

File Upload Failure Handling
  • Loading branch information
MichaelRoeder authored Aug 23, 2024
2 parents a63a8e3 + 18d22a0 commit 8539b7d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/main/java/org/aksw/gerbil/transfer/FileMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/**
* Container file to upload files with blueimp/jQuery plugin
*
*
* @author didier
*
*/
Expand All @@ -36,6 +36,8 @@ public class FileMeta {
private String fileType;
private byte[] bytes;

private String description;

public String getName() {
return name;
}
Expand Down Expand Up @@ -108,4 +110,12 @@ public void setBytes(byte[] bytes) {
this.bytes = bytes;
}


public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}
17 changes: 15 additions & 2 deletions src/main/java/org/aksw/gerbil/web/FileUploadController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@

import javax.servlet.http.HttpServletResponse;

import org.aksw.gerbil.dataset.impl.nif.FileBasedNIFDataset;
import org.aksw.gerbil.exceptions.GerbilException;
import org.aksw.gerbil.transfer.FileMeta;
import org.aksw.gerbil.transfer.UploadFileContainer;
import org.apache.jena.riot.Lang;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -92,9 +95,19 @@ public ModelAndView upload() {
}
files.add(fileContainer);
}

boolean isErroneousFile = false;
for(FileMeta file:files){
try{
FileBasedNIFDataset dataset = new FileBasedNIFDataset(path+file.getName(), file.getName(), Lang.TTL);
dataset.init();
file.setDescription("Found "+dataset.getInstances().size()+" Instances");
}catch(Exception e){
isErroneousFile =true;
file.setError(e.getMessage());
}
}
UploadFileContainer uploadFileContainer = new UploadFileContainer(files);
return new ResponseEntity<UploadFileContainer>(uploadFileContainer, HttpStatus.OK);
return new ResponseEntity<UploadFileContainer>(uploadFileContainer, isErroneousFile?HttpStatus.BAD_REQUEST:HttpStatus.OK);
}

private void createFolderIfNotExists() {
Expand Down
28 changes: 24 additions & 4 deletions src/main/webapp/WEB-INF/views/config.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,9 @@
+ name
+ "("
+ file.name
+ ")</span></li>");
+ ") : "
+ file.description
+ "</span></li>");
var listItems = $('#datasetList > li > span');
for (var i = 0; i < listItems.length; i++) {
listItems[i].onclick = function() {
Expand All @@ -646,9 +648,27 @@
$('#progress .progress-bar').css('width',
progress + '%');
},
processfail : function(e, data) {
alert(data.files[data.index].name + "\n"
+ data.files[data.index].error);
fail : function(e, data) {
data = data.response().jqXHR.responseJSON;
var name = $('#nameDataset').val();
$
.each(
data.files,
function(index, file) {
$('#datasetList')
.append(
"<li><span class=\"glyphicon glyphicon-ban-circle\"></span>&nbsp<span class=\"li_content\">"
+ name
+ "("
+ file.name
+ ") :"
+ file.error
+ "</span></li>");
$('#nameDataset').val(
'');
$('#URIDataset')
.val('');
});
}
}).prop('disabled', !$.support.fileInput).parent()
.addClass($.support.fileInput ? undefined : 'disabled');
Expand Down

0 comments on commit 8539b7d

Please sign in to comment.