Search in sources :

Example 1 with ArticleIngestionView

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);
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) Archive(org.ambraproject.rhino.util.Archive) InputStream(java.io.InputStream) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArticleIngestionView(org.ambraproject.rhino.view.article.ArticleIngestionView) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

InputStream (java.io.InputStream)1 ManifestXml (org.ambraproject.rhino.content.xml.ManifestXml)1 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)1 RestClientException (org.ambraproject.rhino.rest.RestClientException)1 Archive (org.ambraproject.rhino.util.Archive)1 ArticleIngestionView (org.ambraproject.rhino.view.article.ArticleIngestionView)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1