use of org.ambraproject.rhino.view.article.ArticleIngestionView in project rhino by PLOS.
the class IngestibleZipController method zipUpload.
/**
* Create an article based on a POST containing an article .zip archive file.
*
* @param requestFile body of the archive param, with the encoded article .zip file
* @throws java.io.IOException
*/
@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/articles", method = RequestMethod.POST)
public ResponseEntity<?> zipUpload(@RequestParam(value = "archive", required = true) MultipartFile requestFile, @RequestParam(value = "bucket", required = false) String bucket) throws IOException {
String ingestedFileName = requestFile.getOriginalFilename();
ArticleIngestion ingestion;
try (InputStream requestInputStream = requestFile.getInputStream();
Archive archive = Archive.readZipFile(ingestedFileName, requestInputStream)) {
ingestion = ingestionService.ingest(archive, Optional.ofNullable(bucket));
} catch (ManifestXml.ManifestDataException e) {
throw new RestClientException("Invalid manifest: " + e.getMessage(), HttpStatus.BAD_REQUEST, e);
}
// Report the written data, as JSON, in the response.
ArticleIngestionView view = articleIngestionViewFactory.getView(ingestion);
return ServiceResponse.reportCreated(view).asJsonResponse(entityGson);
}
Aggregations