Search in sources :

Example 1 with ArticleIngestion

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

the class HibernatePersistenceServiceImpl method persistIngestion.

@Override
public ArticleIngestion persistIngestion(Article article, ArticleMetadata articleMetadata, ArticleCustomMetadata customMetadata) {
    Journal journal = fetchJournal(articleMetadata);
    int nextIngestionNumber = hibernateTemplate.execute(session -> {
        Query findNextIngestionNumber = session.createQuery("SELECT MAX(ingestionNumber) FROM ArticleIngestion WHERE article = :article");
        findNextIngestionNumber.setParameter("article", article);
        Number maxIngestionNumber = (Number) findNextIngestionNumber.uniqueResult();
        return (maxIngestionNumber == null) ? FIRST_INGESTION_NUMBER : maxIngestionNumber.intValue() + 1;
    });
    ArticleIngestion ingestion = new ArticleIngestion();
    ingestion.setArticle(article);
    ingestion.setIngestionNumber(nextIngestionNumber);
    ingestion.setTitle(articleMetadata.getTitle());
    ingestion.setPublicationDate(java.sql.Date.valueOf(articleMetadata.getPublicationDate()));
    ingestion.setArticleType(articleMetadata.getArticleType());
    ingestion.setJournal(journal);
    ingestion.setRevisionDate((customMetadata.getRevisionDate() == null ? null : java.sql.Date.valueOf(customMetadata.getRevisionDate())));
    ingestion.setPublicationStage(customMetadata.getPublicationStage());
    hibernateTemplate.save(ingestion);
    return ingestion;
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) Query(org.hibernate.Query) Journal(org.ambraproject.rhino.model.Journal)

Example 2 with ArticleIngestion

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

the class IngestionService method persistArticle.

private ArticleIngestion persistArticle(IngestPackage ingestPackage, Doi doi, ArticlePackage articlePackage) {
    Article article = hibernatePersistenceService.persistArticle(doi);
    ArticleIngestion ingestion = hibernatePersistenceService.persistIngestion(article, ingestPackage.getArticleMetadata(), ingestPackage.getArticleCustomMetadata());
    hibernatePersistenceService.persistAssets(articlePackage, ingestion);
    hibernateTemplate.flush();
    // Pick up auto-persisted timestamp
    hibernateTemplate.refresh(ingestion);
    return ingestion;
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) Article(org.ambraproject.rhino.model.Article)

Example 3 with ArticleIngestion

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

the class ArticleOverview method build.

public static ArticleOverview build(ArticleIdentifier articleId, Collection<ArticleIngestion> ingestions, Collection<ArticleRevision> revisions) {
    // Initialize every ingestion number with an empty list of revisions, then fill in revisions.
    Map<Integer, Collection<Integer>> ingestionTable = ingestions.stream().collect(Collectors.toMap(ArticleIngestion::getIngestionNumber, ingestion -> new ArrayList<>(1)));
    for (ArticleRevision revision : revisions) {
        int ingestionKey = revision.getIngestion().getIngestionNumber();
        ingestionTable.get(ingestionKey).add(revision.getRevisionNumber());
    }
    Map<Integer, Integer> revisionTable = revisions.stream().collect(Collectors.toMap(ArticleRevision::getRevisionNumber, revision -> revision.getIngestion().getIngestionNumber()));
    return new ArticleOverview(articleId, Maps.transformValues(ingestionTable, ImmutableSortedSet::copyOf), revisionTable);
}
Also used : ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Collection(java.util.Collection) Map(java.util.Map) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) ArrayList(java.util.ArrayList) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 4 with ArticleIngestion

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

the class SolrIndexServiceImpl method updateSolrIndex.

@Override
public void updateSolrIndex(ArticleIdentifier articleId) {
    Article article = articleCrudService.readArticle(articleId);
    ArticleIngestion ingestion = articleCrudService.readLatestRevision(article).getIngestion();
    Document doc = articleCrudService.getManuscriptXml(ingestion);
    doc = appendJournals(doc, ingestion);
    doc = appendStrikingImage(doc, ingestion);
    String destination = runtimeConfiguration.getQueueConfiguration().getSolrUpdate();
    if (destination == null) {
        throw new RuntimeException("solrUpdate is not configured");
    }
    messageSender.sendBody(destination, doc);
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) Article(org.ambraproject.rhino.model.Article) Document(org.w3c.dom.Document)

Example 5 with ArticleIngestion

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

the class ArticleCrudServiceImpl method serveOverview.

@Override
public ServiceResponse<ArticleOverview> serveOverview(ArticleIdentifier id) {
    ArticleOverview view = hibernateTemplate.execute(session -> {
        Query ingestionQuery = session.createQuery("FROM ArticleIngestion WHERE article.doi = :doi");
        ingestionQuery.setParameter("doi", id.getDoiName());
        List<ArticleIngestion> ingestions = ingestionQuery.list();
        Query revisionQuery = session.createQuery("" + "FROM ArticleRevision WHERE ingestion IN " + "  (FROM ArticleIngestion WHERE article.doi = :doi)");
        revisionQuery.setParameter("doi", id.getDoiName());
        List<ArticleRevision> revisions = revisionQuery.list();
        return ArticleOverview.build(id, ingestions, revisions);
    });
    return ServiceResponse.serveView(view);
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Query(org.hibernate.Query) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview)

Aggregations

ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)16 Article (org.ambraproject.rhino.model.Article)7 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)7 Query (org.hibernate.Query)6 ArticleItem (org.ambraproject.rhino.model.ArticleItem)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)3 Journal (org.ambraproject.rhino.model.Journal)3 Document (org.w3c.dom.Document)3 InputStream (java.io.InputStream)2 Optional (java.util.Optional)2 ManifestXml (org.ambraproject.rhino.content.xml.ManifestXml)2 ArticleFile (org.ambraproject.rhino.model.ArticleFile)2 RestClientException (org.ambraproject.rhino.rest.RestClientException)2 ArticleOverview (org.ambraproject.rhino.view.article.ArticleOverview)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ImmutableList (com.google.common.collect.ImmutableList)1