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);
}
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();
});
}
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;
}
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());
}
}
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;
}
Aggregations