Search in sources :

Example 1 with Archive

use of org.ambraproject.rhino.util.Archive 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)

Example 2 with Archive

use of org.ambraproject.rhino.util.Archive in project rhino by PLOS.

the class SolrIndexServiceTest method testPublication.

@Test(enabled = false)
public void testPublication() throws Exception {
    Archive archive = Archive.readZipFileIntoMemory(new File(TEST_DATA_DIR + "pone.0056489.zip"));
    //    Article article = articleCrudService.writeArchive(archive,
    //        Optional.empty(), DoiBasedCrudService.WriteMode.CREATE_ONLY, OptionalInt.empty());
    Article article = new Article();
    ArticleIdentifier articleId = ArticleIdentifier.create(article.getDoi());
    SolrIndexServiceImpl impl = (SolrIndexServiceImpl) solrIndexService;
    DummyMessageSender dummySender = (DummyMessageSender) impl.messageSender;
    assertEquals(dummySender.messagesSent.size(), 5);
    List<String> solrMessages = dummySender.messagesSent.get("activemq:fake.indexing.queue");
    assertEquals(solrMessages.size(), 1);
    XMLUnit.compareXML(IOUtils.toString(new FileInputStream(TEST_DATA_DIR + "pone.0056489_solr_decorated.xml")), solrMessages.get(0));
    String expectedSyndication = "<ambraMessage><doi>info:doi/10.1371/journal.pone.0056489</doi><archive>pone.0056489.zip</archive></ambraMessage>";
    List<String> crossRefMessages = dummySender.messagesSent.get("activemq:fake.crossref.queue");
    assertEquals(crossRefMessages.size(), 1);
    XMLUnit.compareXML(expectedSyndication, crossRefMessages.get(0));
    List<String> pmcMessages = dummySender.messagesSent.get("activemq:fake.pmc.queue");
    assertEquals(pmcMessages.size(), 1);
    XMLUnit.compareXML(expectedSyndication, pmcMessages.get(0));
    List<String> pubmedMessages = dummySender.messagesSent.get("activemq:fake.pubmed.queue");
    assertEquals(pubmedMessages.size(), 1);
    XMLUnit.compareXML(expectedSyndication, pubmedMessages.get(0));
    solrIndexService.removeSolrIndex(articleId);
    assertEquals(dummySender.messagesSent.size(), 6);
    List<String> deletionMessages = dummySender.messagesSent.get("activemq:fake.delete.queue");
    assertEquals(deletionMessages.size(), 1);
    assertEquals(deletionMessages.get(0), article.getDoi());
}
Also used : Archive(org.ambraproject.rhino.util.Archive) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) SolrIndexServiceImpl(org.ambraproject.rhino.service.impl.SolrIndexServiceImpl) Article(org.ambraproject.rhino.model.Article) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test) BaseRhinoTest(org.ambraproject.rhino.BaseRhinoTest)

Example 3 with Archive

use of org.ambraproject.rhino.util.Archive in project rhino by PLOS.

the class IngestibleController method repack.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/articles/{doi}/ingestions/{number}/ingestible", method = RequestMethod.GET)
public void repack(HttpServletResponse response, @PathVariable("doi") String doi, @PathVariable("number") int ingestionNumber) throws IOException {
    ArticleIngestionIdentifier ingestionId = ArticleIngestionIdentifier.create(DoiEscaping.unescape(doi), ingestionNumber);
    Archive archive = articleCrudService.repack(ingestionId);
    response.setStatus(HttpStatus.OK.value());
    response.setContentType("application/zip");
    response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "filename=" + archive.getArchiveName());
    try (OutputStream outputStream = response.getOutputStream()) {
        archive.write(outputStream);
    }
}
Also used : Archive(org.ambraproject.rhino.util.Archive) ArticleIngestionIdentifier(org.ambraproject.rhino.identity.ArticleIngestionIdentifier) OutputStream(java.io.OutputStream) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Archive

use of org.ambraproject.rhino.util.Archive in project rhino by PLOS.

the class IngestionServiceTest method testGetManifestXml_missingManifest.

@Test(dataProvider = "getPackageEntryNames", expectedExceptions = RestClientException.class, expectedExceptionsMessageRegExp = "Archive has no manifest file")
public void testGetManifestXml_missingManifest(Collection<String> entryNames) throws Exception {
    entryNames.remove("manifest.xml");
    Archive invalidTestArchive = createStubArchive(null, entryNames);
    ingestionService.getManifestXml(invalidTestArchive);
}
Also used : Archive(org.ambraproject.rhino.util.Archive) Test(org.testng.annotations.Test)

Example 5 with Archive

use of org.ambraproject.rhino.util.Archive in project rhino by PLOS.

the class IngestionServiceTest method testGetManifestXml.

@Test(dataProvider = "getPackageEntryNames", expectedExceptions = RestClientException.class, expectedExceptionsMessageRegExp = ".*Invalid XML: Premature end of file.")
public void testGetManifestXml(Collection<String> entryNames) throws Exception {
    Archive invalidTestArchive = createStubArchive(new byte[] {}, entryNames);
    ingestionService.getManifestXml(invalidTestArchive);
}
Also used : Archive(org.ambraproject.rhino.util.Archive) Test(org.testng.annotations.Test)

Aggregations

Archive (org.ambraproject.rhino.util.Archive)5 Test (org.testng.annotations.Test)3 Transactional (org.springframework.transaction.annotation.Transactional)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 BaseRhinoTest (org.ambraproject.rhino.BaseRhinoTest)1 ManifestXml (org.ambraproject.rhino.content.xml.ManifestXml)1 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)1 ArticleIngestionIdentifier (org.ambraproject.rhino.identity.ArticleIngestionIdentifier)1 Article (org.ambraproject.rhino.model.Article)1 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)1 RestClientException (org.ambraproject.rhino.rest.RestClientException)1 SolrIndexServiceImpl (org.ambraproject.rhino.service.impl.SolrIndexServiceImpl)1 ArticleIngestionView (org.ambraproject.rhino.view.article.ArticleIngestionView)1