Search in sources :

Example 26 with Article

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

the class CommentCrudServiceImpl method serveComments.

@Override
public ServiceResponse<List<CommentOutputView>> serveComments(ArticleIdentifier articleId) throws IOException {
    Article article = articleCrudService.readArticle(articleId);
    Collection<Comment> comments = fetchAllComments(article);
    CommentOutputView.Factory factory = new CommentOutputView.Factory(new CompetingInterestPolicy(runtimeConfiguration), comments, article);
    List<CommentOutputView> views = comments.stream().filter(comment -> comment.getParent() == null).sorted(CommentOutputView.BY_DATE).map(factory::buildView).collect(Collectors.toList());
    return ServiceResponse.serveView(views);
}
Also used : CompetingInterestPolicy(org.ambraproject.rhino.view.comment.CompetingInterestPolicy) Flag(org.ambraproject.rhino.model.Flag) ServiceResponse(org.ambraproject.rhino.rest.response.ServiceResponse) CommentCrudService(org.ambraproject.rhino.service.CommentCrudService) Article(org.ambraproject.rhino.model.Article) Journal(org.ambraproject.rhino.model.Journal) CacheableResponse(org.ambraproject.rhino.rest.response.CacheableResponse) CommentFlagInputView(org.ambraproject.rhino.view.comment.CommentFlagInputView) JournalCrudService(org.ambraproject.rhino.service.JournalCrudService) RestClientException(org.ambraproject.rhino.rest.RestClientException) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) Strings(com.google.common.base.Strings) Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) CommentNodeView(org.ambraproject.rhino.view.comment.CommentNodeView) CommentIdentifier(org.ambraproject.rhino.identity.CommentIdentifier) CommentFlagOutputView(org.ambraproject.rhino.view.comment.CommentFlagOutputView) CommentOutputView(org.ambraproject.rhino.view.comment.CommentOutputView) Query(org.hibernate.Query) Doi(org.ambraproject.rhino.identity.Doi) HibernateCallback(org.springframework.orm.hibernate3.HibernateCallback) CommentCountView(org.ambraproject.rhino.view.comment.CommentCountView) Collection(java.util.Collection) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) HttpStatus(org.springframework.http.HttpStatus) ArticleCrudService(org.ambraproject.rhino.service.ArticleCrudService) List(java.util.List) CommentInputView(org.ambraproject.rhino.view.comment.CommentInputView) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) FlagReasonCode(org.ambraproject.rhino.model.FlagReasonCode) Pattern(java.util.regex.Pattern) Comment(org.ambraproject.rhino.model.Comment) Comment(org.ambraproject.rhino.model.Comment) Article(org.ambraproject.rhino.model.Article) CommentOutputView(org.ambraproject.rhino.view.comment.CommentOutputView) CompetingInterestPolicy(org.ambraproject.rhino.view.comment.CompetingInterestPolicy)

Example 27 with Article

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

the class IssueOutputView method getIssueImageFigureDoi.

private static String getIssueImageFigureDoi(ArticleCrudService articleCrudService, Article imageArticle) {
    ArticleRevision latestArticleRevision = articleCrudService.getLatestRevision(imageArticle).orElseThrow(() -> new RuntimeException("Image article has no published revisions. " + imageArticle.getDoi()));
    ArticleIngestion ingestion = latestArticleRevision.getIngestion();
    Collection<ArticleItem> allArticleItems = articleCrudService.getAllArticleItems(ingestion);
    List<ArticleItem> figureImageItems = allArticleItems.stream().filter(item -> FIGURE_IMAGE_TYPES.contains(item.getItemType())).collect(Collectors.toList());
    if (figureImageItems.size() != 1) {
        throw new RuntimeException("Image article does not contain exactly one image file. " + imageArticle.getDoi());
    }
    return figureImageItems.get(0).getDoi();
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleItem(org.ambraproject.rhino.model.ArticleItem) JsonObject(com.google.gson.JsonObject) ArticleItem(org.ambraproject.rhino.model.ArticleItem) ImmutableSet(com.google.common.collect.ImmutableSet) Article(org.ambraproject.rhino.model.Article) Journal(org.ambraproject.rhino.model.Journal) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) JsonOutputView(org.ambraproject.rhino.view.JsonOutputView) JsonElement(com.google.gson.JsonElement) Objects(java.util.Objects) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) ArticleCrudService(org.ambraproject.rhino.service.ArticleCrudService) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Issue(org.ambraproject.rhino.model.Issue) Volume(org.ambraproject.rhino.model.Volume) JsonSerializationContext(com.google.gson.JsonSerializationContext) Optional(java.util.Optional) IssueCrudService(org.ambraproject.rhino.service.IssueCrudService) ArticleRevisionView(org.ambraproject.rhino.view.article.ArticleRevisionView)

Example 28 with Article

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

the class TaxonomyClassificationServiceImpl method populateCategories.

/**
   * {@inheritDoc}
   */
@Override
public void populateCategories(ArticleRevision revision) {
    ArticleIngestion ingestion = revision.getIngestion();
    Article article = ingestion.getArticle();
    Document xml = articleCrudService.getManuscriptXml(ingestion);
    List<WeightedTerm> terms;
    String doi = article.getDoi();
    //todo: fix or remove this when we find a home for article types
    boolean isAmendment = false;
    if (!isAmendment) {
        terms = classifyArticle(article, xml);
        if (terms != null && terms.size() > 0) {
            List<WeightedTerm> leafNodes = getDistinctLeafNodes(CATEGORY_COUNT, terms);
            persistCategories(leafNodes, article);
        } else {
            log.error("Taxonomy server returned 0 terms. Cannot populate Categories. " + doi);
        }
    }
}
Also used : ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) WeightedTerm(org.ambraproject.rhino.service.taxonomy.WeightedTerm) Article(org.ambraproject.rhino.model.Article) Document(org.w3c.dom.Document)

Example 29 with Article

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

the class HibernatePersistenceServiceImpl method persistArticle.

@Override
public Article persistArticle(Doi doi) {
    String articleDoi = doi.getName();
    Article article = hibernateTemplate.execute(session -> {
        Query selectQuery = session.createQuery("FROM Article WHERE doi = :doi");
        selectQuery.setParameter("doi", articleDoi);
        return (Article) selectQuery.uniqueResult();
    });
    if (article == null) {
        article = new Article();
        article.setDoi(articleDoi);
        hibernateTemplate.save(article);
    }
    return article;
}
Also used : Query(org.hibernate.Query) Article(org.ambraproject.rhino.model.Article)

Example 30 with Article

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

the class IngestionServiceTest method createStubArticleItem.

private static ArticleItem createStubArticleItem() {
    ArticleItem articleItem = new ArticleItem();
    ArticleIngestion articleIngestion = new ArticleIngestion();
    Article article = new Article();
    article.setDoi("test");
    articleItem.setIngestion(articleIngestion);
    articleIngestion.setArticle(article);
    return articleItem;
}
Also used : ArticleItem(org.ambraproject.rhino.model.ArticleItem) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) Article(org.ambraproject.rhino.model.Article)

Aggregations

Article (org.ambraproject.rhino.model.Article)31 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)10 ArticleIdentifier (org.ambraproject.rhino.identity.ArticleIdentifier)9 List (java.util.List)8 ArticleIngestion (org.ambraproject.rhino.model.ArticleIngestion)8 RestClientException (org.ambraproject.rhino.rest.RestClientException)7 Document (org.w3c.dom.Document)7 IOException (java.io.IOException)6 Optional (java.util.Optional)6 Query (org.hibernate.Query)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Collection (java.util.Collection)5 Collectors (java.util.stream.Collectors)5 ArticleCrudService (org.ambraproject.rhino.service.ArticleCrudService)5 LocalDate (java.time.LocalDate)4 ArrayList (java.util.ArrayList)4 Doi (org.ambraproject.rhino.identity.Doi)4 ArticleCategoryAssignment (org.ambraproject.rhino.model.ArticleCategoryAssignment)4 CacheableResponse (org.ambraproject.rhino.rest.response.CacheableResponse)4 HttpStatus (org.springframework.http.HttpStatus)4