Skip to content
Snippets Groups Projects
Commit 1fe53e39 authored by LouisGendron's avatar LouisGendron
Browse files

Improved validation of 'dataset' parameter in 'file_upload'

parent 7c785cac
No related branches found
No related tags found
1 merge request!3Resolve "fetch files annotations when download dataset"
......@@ -170,27 +170,48 @@ setMethod(
# Upload file
setGeneric(
name="file_upload",
def=function(object, session, file_path, annotation='', lab='', dataset=''){
def=function(object, session, file_path, annotations='', lab='', dataset=''){
standardGeneric("file_upload")
}
)
setMethod(
f='file_upload',
signature='IRICData',
definition=function(object, session, file_path, annotation='', lab='', dataset=''){
definition=function(object, session, file_path, annotations='', lab='', dataset=''){
error=FALSE
#Check if annotation can be parsed as JSON
if (typeof(annotation) == 'list'){annotation <- toJSON(annotation)}
else if (typeof(annotation) == 'character'){
validation = jsonlite::validate(annotation)
if (typeof(annotations) == 'list'){annotations <- toJSON(annotation)}
else if (typeof(annotations) == 'character'){
validation = jsonlite::validate(annotations)
if(!(validation[[1]])){
print(paste('Error occured while uploading', file_path,
': the annotation parameter could not be parsed as JSON'))
return(NULL)
error=TRUE
}
}
#TO DO : check is lab is available
#Check if dataset is available
if (dataset !='') {
datasets = get_available_dataset(object, session)
if(!(dataset %in% datasets$Slug_id)){
print("ERROR : 'dataset' parameter does not match of any of the available dataset, try get_available_dataset(client, session) for more details.")
error=TRUE
}else{#Check if the file is already in the dataset
dataset_details = get_dataset_hash(IData, IData_session, dataset)
if(file_name %in% dataset_details$file_name){
print(paste('WARNING : file', file_name, 'already exist in the selected dataset.'))
}
}
}
if (error){
return(NULL)
}
file_form = list(file=httr::upload_file(file_path),
lab=lab, annotations=annotation, dataset=dataset)
lab=lab, annotations=annotations, dataset=dataset)
session = rvest:::request_POST(x=IData_session, body=file_form,
url=paste(object@url,'secure/servlet/datafiles/upload', sep='/'))
......@@ -254,7 +275,7 @@ setMethod(
definition=function(object, session){
resp = rvest::jump_to(IData_session , paste(IData@url, 'secure/my-datasets/list/json/', sep='/'))
output = as.data.frame(jsonlite::fromJSON(rawToChar(resp$response$content)))
names(output) = c('Name','Slug_id')
names(output) = c('Dataset_name','Dataset_slug')
return(output)
}
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment