Search in sources :

Example 1 with ArticleRevision

use of org.ambraproject.rhino.model.ArticleRevision 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 2 with ArticleRevision

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

the class SyndicationCrudServiceImpl method getSyndications.

@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
@Override
public List<Syndication> getSyndications(ArticleRevisionIdentifier revisionId) {
    ArticleRevision articleRevision = articleCrudService.readRevision(revisionId);
    return hibernateTemplate.execute(session -> {
        Query query = session.createQuery("" + "FROM Syndication s " + "WHERE s.articleRevision = :articleRevision");
        query.setParameter("articleRevision", articleRevision);
        return (List<Syndication>) query.list();
    });
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Query(org.hibernate.Query) List(java.util.List) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ArticleRevision

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

the class SyndicationCrudServiceImpl method createSyndication.

@Override
public Syndication createSyndication(ArticleRevisionIdentifier revisionId, String syndicationTargetQueue) {
    ArticleRevision articleVersion = articleCrudService.readRevision(revisionId);
    Syndication syndication = new Syndication(articleVersion, syndicationTargetQueue);
    syndication.setStatus(SyndicationStatus.PENDING.getLabel());
    syndication.setSubmissionCount(0);
    hibernateTemplate.save(syndication);
    return syndication;
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Syndication(org.ambraproject.rhino.model.Syndication)

Example 4 with ArticleRevision

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

the class SyndicationCrudServiceImpl method syndicate.

@Transactional(rollbackFor = { Throwable.class })
@Override
public Syndication syndicate(ArticleRevisionIdentifier revisionId, String syndicationTargetQueue) {
    ArticleRevision articleVersion = articleCrudService.readRevision(revisionId);
    Syndication syndication = getSyndication(revisionId, syndicationTargetQueue);
    if (syndication == null) {
        syndication = new Syndication(articleVersion, syndicationTargetQueue);
        syndication.setStatus(SyndicationStatus.IN_PROGRESS.getLabel());
        syndication.setSubmissionCount(1);
        syndication.setLastSubmitTimestamp(new Date());
        hibernateTemplate.save(syndication);
    } else {
        syndication.setStatus(SyndicationStatus.IN_PROGRESS.getLabel());
        syndication.setSubmissionCount(syndication.getSubmissionCount() + 1);
        syndication.setLastSubmitTimestamp(new Date());
        hibernateTemplate.update(syndication);
    }
    try {
        messageSender.sendBody(syndicationTargetQueue, createBody(revisionId));
        log.info("Successfully sent a Message to plos-queue for {} to be syndicated to {}", revisionId, syndicationTargetQueue);
        return syndication;
    } catch (Exception e) {
        log.warn("Error syndicating " + revisionId + " to " + syndicationTargetQueue, e);
        return updateSyndication(revisionId, syndicationTargetQueue, SyndicationStatus.FAILURE.getLabel(), e.getMessage());
    }
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Syndication(org.ambraproject.rhino.model.Syndication) Date(java.util.Date) LocalDate(java.time.LocalDate) IOException(java.io.IOException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with ArticleRevision

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

the class ArticleRevisionView method serialize.

@Override
public JsonElement serialize(JsonSerializationContext context) {
    JsonObject serialized = new JsonObject();
    serialized.addProperty("doi", article.getDoi());
    this.revision.ifPresent((ArticleRevision revision) -> {
        serialized.addProperty("revisionNumber", revision.getRevisionNumber());
        serialized.add("ingestion", serializeIngestion(context, revision.getIngestion()));
    });
    return serialized;
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) JsonObject(com.google.gson.JsonObject)

Aggregations

ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)20 Article (org.ambraproject.rhino.model.Article)9 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)9 Query (org.hibernate.Query)7 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Collection (java.util.Collection)4 Collectors (java.util.stream.Collectors)4 ArticleItem (org.ambraproject.rhino.model.ArticleItem)4 IOException (java.io.IOException)3 LocalDate (java.time.LocalDate)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 ArticleIngestionIdentifier (org.ambraproject.rhino.identity.ArticleIngestionIdentifier)3 ArticleOverview (org.ambraproject.rhino.view.article.ArticleOverview)3 ArticleRevisionView (org.ambraproject.rhino.view.article.ArticleRevisionView)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Document (org.w3c.dom.Document)3