use of org.springframework.web.multipart.MultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFile.
@Test
public void resolveMultipartFile() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("mfile", "Hello World".getBytes());
request.addFile(expected);
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
boolean condition = result instanceof MultipartFile;
assertThat(condition).isTrue();
assertThat(result).as("Invalid result").isEqualTo(expected);
}
use of org.springframework.web.multipart.MultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileNotAnnot.
@Test
public void resolveMultipartFileNotAnnot() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("multipartFileNotAnnot", "Hello World".getBytes());
request.addFile(expected);
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotNotPresent().arg(MultipartFile.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
boolean condition = result instanceof MultipartFile;
assertThat(condition).isTrue();
assertThat(result).as("Invalid result").isEqualTo(expected);
}
use of org.springframework.web.multipart.MultipartFile in project spring-framework by spring-projects.
the class StandardMultipartHttpServletRequestTests method filename.
@Test
public void filename() throws Exception {
String disposition = "form-data; name=\"file\"; filename=\"myFile.txt\"";
StandardMultipartHttpServletRequest request = requestWithPart("file", disposition, "");
MultipartFile multipartFile = request.getFile("file");
assertThat(multipartFile).isNotNull();
assertThat(multipartFile.getOriginalFilename()).isEqualTo("myFile.txt");
}
use of org.springframework.web.multipart.MultipartFile in project goci by EBISPOT.
the class DiseaseTraitUploadController method updloadDiseaseTraits.
@PostMapping("/uploads")
public Object updloadDiseaseTraits(@Valid FileUploadRequest fileUploadRequest, BindingResult result) {
if (result.hasErrors()) {
throw new FileValidationException(result);
}
MultipartFile multipartFile = fileUploadRequest.getMultipartFile();
List<DiseaseTrait> diseaseTraits = DiseaseTraitDtoAssembler.disassemble(multipartFile);
diseaseTraits = diseaseTraitService.createDiseaseTraits(diseaseTraits);
log.info("{} {} were created", diseaseTraits.size(), EntityType.DISEASE_TRAIT);
return new ResponseEntity<>(DiseaseTraitDtoAssembler.assemble(diseaseTraits), HttpStatus.CREATED);
}
use of org.springframework.web.multipart.MultipartFile in project goci by EBISPOT.
the class AssociationUploadService method upload.
@Transactional(readOnly = false)
public List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user) throws IOException, EnsemblMappingException {
int s = study.getEvents().size();
if (s > 0) {
getLog().trace("Study " + study.getId().toString() + " has " + s + " events");
}
// File errors will contain any validation errors and be returned to controller if any are found
List<AssociationUploadErrorView> fileErrors = new ArrayList<>();
String originalFilename = file.getOriginalFilename();
getLog().info("Uploading file: ".concat(originalFilename));
// Upload file
try {
uploadFile(file, study.getId());
// Send file, including path, to SNP batch loader process
File uploadedFile = studyFileService.getFileFromFileName(study.getId(), originalFilename);
ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(uploadedFile, "full");
if (validationSummary != null) {
// Check if we have any row errors
long rowErrorCount = validationSummary.getRowValidationSummaries().parallelStream().filter(rowValidationSummary -> !rowValidationSummary.getErrors().isEmpty()).count();
// Errors found
if (rowErrorCount > 0) {
studyFileService.deleteFile(study.getId(), originalFilename);
getLog().error("Row errors found in file: " + originalFilename);
validationSummary.getRowValidationSummaries().forEach(rowValidationSummary -> fileErrors.addAll(processRowError(rowValidationSummary)));
} else {
// Determine if we have any errors rather than warnings
// Errors prevent saving association
List<ValidationError> allAssociationsErrors = new ArrayList<>();
validationSummary.getAssociationSummaries().forEach(associationSummary -> allAssociationsErrors.addAll(associationSummary.getErrors()));
long associationErrorCount = allAssociationsErrors.parallelStream().filter(validationError -> !validationError.getWarning()).count();
if (associationErrorCount > 0) {
studyFileService.deleteFile(study.getId(), originalFilename);
getLog().error("Association errors found in file: " + originalFilename);
validationSummary.getAssociationSummaries().forEach(associationSummary -> fileErrors.addAll(processAssociationError(associationSummary)));
} else {
Integer numberOfAssociations = validationSummary.getAssociationSummaries().size();
String description = numberOfAssociations.toString().concat(" associations created from upload of '").concat(originalFilename).concat("'");
createBatchUploadEvent(study, description, user);
saveAssociations(validationSummary.getAssociationSummaries(), study, user);
}
}
}
return fileErrors;
} catch (IOException e) {
throw new IOException(e);
}
}
Aggregations