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