Search in sources :

Example 11 with Doi

use of org.ambraproject.rhino.identity.Doi in project rhino by PLOS.

the class HibernatePersistenceServiceImpl method persistStrikingImage.

@Override
public Optional<ArticleItem> persistStrikingImage(ArticleIngestion ingestion, List<ArticleItem> items, ManifestXml manifest) {
    Optional<ManifestXml.Asset> strikingImageAsset = manifest.getAssets().stream().filter(ManifestXml.Asset::isStrikingImage).findAny();
    if (!strikingImageAsset.isPresent()) {
        // No striking image declared, so go without setting one.
        return Optional.empty();
    }
    Doi strikingImageDoi = Doi.create(strikingImageAsset.get().getUri());
    Optional<ArticleItem> strikingImageItem = items.stream().filter(item -> Doi.create(item.getDoi()).equals(strikingImageDoi)).findAny();
    if (!strikingImageItem.isPresent()) {
        throw new RuntimeException("Striking image from manifest not found (should have been created by now)");
    }
    ingestion.setStrikingImage(strikingImageItem.get());
    hibernateTemplate.update(ingestion);
    return strikingImageItem;
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticlePackage(org.ambraproject.rhino.model.ingest.ArticlePackage) Article(org.ambraproject.rhino.model.Article) Journal(org.ambraproject.rhino.model.Journal) JournalCrudService(org.ambraproject.rhino.service.JournalCrudService) HibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate) Collection(java.util.Collection) RestClientException(org.ambraproject.rhino.rest.RestClientException) HibernatePersistenceService(org.ambraproject.rhino.service.HibernatePersistenceService) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ArticleCustomMetadata(org.ambraproject.rhino.model.article.ArticleCustomMetadata) ContentRepoPersistenceService(org.ambraproject.rhino.service.ContentRepoPersistenceService) HttpStatus(org.springframework.http.HttpStatus) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) List(java.util.List) ArticleItemInput(org.ambraproject.rhino.model.ingest.ArticleItemInput) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml) Query(org.hibernate.Query) Optional(java.util.Optional) Doi(org.ambraproject.rhino.identity.Doi) ArticleFile(org.ambraproject.rhino.model.ArticleFile) ArticleMetadata(org.ambraproject.rhino.model.article.ArticleMetadata) ArticleItem(org.ambraproject.rhino.model.ArticleItem) ManifestXml(org.ambraproject.rhino.content.xml.ManifestXml) Doi(org.ambraproject.rhino.identity.Doi)

Example 12 with Doi

use of org.ambraproject.rhino.identity.Doi in project rhino by PLOS.

the class DoiEscapingTest method testDoiUnescaping.

@Test(dataProvider = "doiEscapingCases")
public void testDoiUnescaping(String expectedUnescape, String escapedDoi, boolean hasUriPrefix) {
    Doi actualUnescape = DoiEscaping.unescape(escapedDoi);
    Assert.assertEquals(actualUnescape, easyResolve(escapedDoi));
    Assert.assertEquals(actualUnescape.getName(), expectedUnescape);
    if (!hasUriPrefix) {
        String actualEscape = DoiEscaping.escape(expectedUnescape);
        Assert.assertEquals(actualEscape, escapedDoi);
    }
}
Also used : Doi(org.ambraproject.rhino.identity.Doi) Test(org.testng.annotations.Test)

Aggregations

Doi (org.ambraproject.rhino.identity.Doi)12 RestClientException (org.ambraproject.rhino.rest.RestClientException)4 Node (org.w3c.dom.Node)4 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)3 Article (org.ambraproject.rhino.model.Article)3 Strings (com.google.common.base.Strings)2 Lists (com.google.common.collect.Lists)2 LocalDate (java.time.LocalDate)2 Optional (java.util.Optional)2 ArticleFile (org.ambraproject.rhino.model.ArticleFile)2 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)2 ArticleItem (org.ambraproject.rhino.model.ArticleItem)2 ArticleMetadata (org.ambraproject.rhino.model.article.ArticleMetadata)2 RelatedArticleLink (org.ambraproject.rhino.model.article.RelatedArticleLink)2 Query (org.hibernate.Query)2 Logger (org.slf4j.Logger)2