use of cern.modesti.request.upload.parser.RequestParseResult in project modesti by jlsalmon.
the class UploadService method parseRequestFromExcelSheet.
/**
* Delegate the parsing of the uploaded Excel sheet to a specific plugin
* implementation.
*
* @param description the description of the uploaded request
* @param stream the Excel sheet to be parsed
* @return the result of the request parse
*/
public RequestParseResult parseRequestFromExcelSheet(String description, InputStream stream) {
RequestParseResult result = requestParserFactory.parseRequest(stream);
Request request = result.getRequest();
if (request.getDescription() == null) {
request.setDescription(description);
}
requestService.insert(request);
return result;
}
use of cern.modesti.request.upload.parser.RequestParseResult in project modesti by jlsalmon.
the class UploadController method handleFileUpload.
@RequestMapping(value = "/api/requests/upload", method = POST)
public ResponseEntity<?> handleFileUpload(@RequestParam("file") MultipartFile file, @RequestParam("description") String description, UriComponentsBuilder b) {
RequestParseResult result;
if (!file.isEmpty()) {
try {
result = service.parseRequestFromExcelSheet(description, file.getInputStream());
log.info("successfully uploaded " + file.getOriginalFilename());
} catch (Exception e) {
log.info("failed to upload " + file.getOriginalFilename(), e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
} else {
log.info("failed to upload " + file.getOriginalFilename() + " because the file was empty.");
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
// Add link to newly created request in Location header
UriComponents uriComponents = b.path("/requests/{id}").buildAndExpand(result.getRequest().getRequestId());
HttpHeaders headers = new HttpHeaders();
headers.setLocation(uriComponents.toUri());
return new ResponseEntity<>(result.getWarnings(), headers, HttpStatus.CREATED);
}
Aggregations