Search in sources :

Example 31 with Article

use of org.ambraproject.rhino.model.Article in project rhino by PLOS.

the class RhinoTestHelper method readReferenceCase.

//  public static Archive createMockIngestible(ArticleIdentity articleId, InputStream xmlData,
//                                             List<ArticleAsset> referenceAssets) {
//    try {
//      try {
//        String archiveName = articleId.getLastToken() + ".zip";
//        InputStream mockIngestible = IngestibleUtil.buildMockIngestible(xmlData, referenceAssets);
//        return Archive.readZipFileIntoMemory(archiveName, mockIngestible);
//      } finally {
//        xmlData.close();
//      }
//    } catch (IOException e) {
//      throw new RuntimeException(e);
//    }
//  }
//  public static Stream<ArticleMetadata> createTestArticles(IngestionService ingestionService) {
//    return SAMPLE_ARTICLES.stream().map(doiStub -> createTestArticle(ingestionService, doiStub));
//  }
//
//  public static ArticleMetadata createTestArticle(IngestionService ingestionService) {
//    return createTestArticle(ingestionService, SAMPLE_ARTICLES.get(0));
//  }
//  public static ArticleMetadata createTestArticle(IngestionService ingestionService, String doiStub) {
//    ArticleIdentity articleId = ArticleIdentity.create(RhinoTestHelper.prefixed(doiStub));
//    RhinoTestHelper.TestFile sampleFile = new RhinoTestHelper.TestFile(getXmlPath(doiStub));
//    String doi = articleId.getIdentifier();
//
//    byte[] sampleData;
//    try {
//      sampleData = IOUtils.toByteArray(RhinoTestHelper.alterStream(sampleFile.read(), doi, doi));
//    } catch (IOException e) {
//      throw new RuntimeException(e);
//    }
//
//    Article reference = readReferenceCase(getJsonPath(doiStub));
//
//    RhinoTestHelper.TestInputStream input = RhinoTestHelper.TestInputStream.of(sampleData);
//    Archive mockIngestible = createMockIngestible(articleId, input, reference.getAssets());
//    ArticleIngestion ingestion;
//    try {
//      ingestion = ingestionService.ingest(mockIngestible);
//    } catch (IOException e) {
//      throw new RuntimeException(e);
//    }
//    return null; // TODO: Recover ArticleMetadata from ArticleIngestionIdentifier
//  }
public static Article readReferenceCase(File jsonFile) {
    Preconditions.checkNotNull(jsonFile);
    Article article;
    try (Reader input = new BufferedReader(new FileReader(jsonFile))) {
        article = new Gson().fromJson(input, Article.class);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return article;
}
Also used : Article(org.ambraproject.rhino.model.Article) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) IOException(java.io.IOException)

Aggregations

Article (org.ambraproject.rhino.model.Article)31 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)10 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)9 List (java.util.List)8 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)8 RestClientException (org.ambraproject.rhino.rest.RestClientException)7 Document (org.w3c.dom.Document)7 IOException (java.io.IOException)6 Optional (java.util.Optional)6 Query (org.hibernate.Query)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Collection (java.util.Collection)5 Collectors (java.util.stream.Collectors)5 ArticleCrudService (org.ambraproject.rhino.service.ArticleCrudService)5 LocalDate (java.time.LocalDate)4 ArrayList (java.util.ArrayList)4 Doi (org.ambraproject.rhino.identity.Doi)4 ArticleCategoryAssignment (org.ambraproject.rhino.model.ArticleCategoryAssignment)4 CacheableResponse (org.ambraproject.rhino.rest.response.CacheableResponse)4 HttpStatus (org.springframework.http.HttpStatus)4