Search in sources :

Example 21 with Article

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

the class ArticleCrudServiceImpl method getRawCategoriesAndText.

/**
   * {@inheritDoc}
   *
   * @param articleId
   */
@Override
public String getRawCategoriesAndText(final ArticleIdentifier articleId) throws IOException {
    Article article = readArticle(articleId);
    ArticleRevision revision = readLatestRevision(article);
    Document manuscriptXml = getManuscriptXml(revision.getIngestion());
    List<String> rawTermsAndText = taxonomyService.getRawTerms(manuscriptXml, article, true);
    StringBuilder cleanedTermsAndText = new StringBuilder();
    cleanedTermsAndText.append("<pre>");
    // HTML-escape the text, which is in the first element of the result array
    cleanedTermsAndText.append(StringEscapeUtils.escapeHtml4(rawTermsAndText.get(0)));
    cleanedTermsAndText.append("\n");
    for (int i = 1; i < rawTermsAndText.size(); i++) {
        String term = rawTermsAndText.get(i).replaceAll("<TERM>", "").replaceAll("</TERM>", "");
        cleanedTermsAndText.append("\n");
        cleanedTermsAndText.append(term);
    }
    cleanedTermsAndText.append("</pre>");
    return cleanedTermsAndText.toString();
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Article(org.ambraproject.rhino.model.Article) Document(org.w3c.dom.Document)

Example 22 with Article

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

the class ArticleCrudServiceImpl method getLatestRevision.

@Override
public Optional<ArticleRevision> getLatestRevision(Article article) {
    Integer maxRevisionNumber = hibernateTemplate.execute(session -> {
        Query query = session.createQuery("" + "SELECT MAX(rev.revisionNumber) " + "FROM ArticleRevision rev, ArticleItem item " + "WHERE item.doi = :doi " + "  AND rev.ingestion = item.ingestion");
        query.setParameter("doi", Doi.create(article.getDoi()).getName());
        return (Integer) query.uniqueResult();
    });
    if (maxRevisionNumber == null)
        return Optional.empty();
    return Optional.ofNullable(hibernateTemplate.execute(session -> {
        Query query = session.createQuery("" + "FROM ArticleRevision as av " + "WHERE av.ingestion.article = :article " + "AND av.revisionNumber = :latestRevision");
        query.setParameter("article", article);
        query.setParameter("latestRevision", maxRevisionNumber);
        return (ArticleRevision) query.uniqueResult();
    }));
}
Also used : ArticleIngestionIdentifier(org.ambraproject.rhino.identity.ArticleIngestionIdentifier) ServiceResponse(org.ambraproject.rhino.rest.response.ServiceResponse) ArticleFileIdentifier(org.ambraproject.rhino.identity.ArticleFileIdentifier) RelatedArticleLink(org.ambraproject.rhino.model.article.RelatedArticleLink) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Collections2(com.google.common.collect.Collections2) Archive(org.ambraproject.rhino.util.Archive) ArticleXml(org.ambraproject.rhino.content.xml.ArticleXml) ArticleIngestion(org.ambraproject.rhino.model.ArticleIngestion) Matcher(java.util.regex.Matcher) Document(org.w3c.dom.Document) Map(java.util.Map) Query(org.hibernate.Query) StringEscapeUtils(org.apache.commons.lang3.StringEscapeUtils) ArticleAllAuthorsView(org.ambraproject.rhino.view.article.author.ArticleAllAuthorsView) ArticleItem(org.ambraproject.rhino.model.ArticleItem) RepoObjectMetadata(org.plos.crepo.model.metadata.RepoObjectMetadata) Collection(java.util.Collection) Set(java.util.Set) ResolvedDoiView(org.ambraproject.rhino.view.ResolvedDoiView) AssetCrudService(org.ambraproject.rhino.service.AssetCrudService) Collectors(java.util.stream.Collectors) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Objects(java.util.Objects) List(java.util.List) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) LocalDate(java.time.LocalDate) Optional(java.util.Optional) ArticleFile(org.ambraproject.rhino.model.ArticleFile) Pattern(java.util.regex.Pattern) ArticleRevisionView(org.ambraproject.rhino.view.article.ArticleRevisionView) ArticleRelationship(org.ambraproject.rhino.model.ArticleRelationship) Iterables(com.google.common.collect.Iterables) Article(org.ambraproject.rhino.model.Article) CacheableResponse(org.ambraproject.rhino.rest.response.CacheableResponse) RestClientException(org.ambraproject.rhino.rest.RestClientException) ArticleOverview(org.ambraproject.rhino.view.article.ArticleOverview) ArticleItemIdentifier(org.ambraproject.rhino.identity.ArticleItemIdentifier) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) TaxonomyService(org.ambraproject.rhino.service.taxonomy.TaxonomyService) XpathReader(org.ambraproject.rhino.content.xml.XpathReader) Doi(org.ambraproject.rhino.identity.Doi) ByteSource(com.google.common.io.ByteSource) XPathException(javax.xml.xpath.XPathException) ArticleIngestionView(org.ambraproject.rhino.view.article.ArticleIngestionView) Logger(org.slf4j.Logger) XmlContentException(org.ambraproject.rhino.content.xml.XmlContentException) IOException(java.io.IOException) ArticleCategoryAssignment(org.ambraproject.rhino.model.ArticleCategoryAssignment) HttpStatus(org.springframework.http.HttpStatus) ArticleCrudService(org.ambraproject.rhino.service.ArticleCrudService) AuthorView(org.ambraproject.rhino.view.article.author.AuthorView) CategoryAssignmentView(org.ambraproject.rhino.view.article.CategoryAssignmentView) ItemSetView(org.ambraproject.rhino.view.article.ItemSetView) InputStream(java.io.InputStream) Query(org.hibernate.Query)

Example 23 with Article

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

the class ArticleCrudServiceImpl method serveRawCategories.

/**
   * {@inheritDoc}
   */
@Override
public ServiceResponse<List<String>> serveRawCategories(final ArticleIdentifier articleId) throws IOException {
    Article article = readArticle(articleId);
    ArticleRevision revision = readLatestRevision(article);
    Document manuscriptXml = getManuscriptXml(revision.getIngestion());
    List<String> rawTerms = taxonomyService.getRawTerms(manuscriptXml, article, false);
    List<String> cleanedTerms = new ArrayList<>();
    for (String term : rawTerms) {
        term = term.replaceAll("<TERM>", "").replaceAll("</TERM>", "");
        cleanedTerms.add(term);
    }
    return ServiceResponse.serveView(cleanedTerms);
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Article(org.ambraproject.rhino.model.Article) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document)

Example 24 with Article

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

the class ArticleCrudServiceImpl method fromRelatedArticleLink.

private ArticleRelationship fromRelatedArticleLink(Article article, RelatedArticleLink ral) {
    ArticleRelationship ar = new ArticleRelationship();
    ar.setSourceArticle(Objects.requireNonNull(article));
    Article targetArticle = getArticle(ral.getArticleId()).orElse(null);
    ar.setTargetArticle(Objects.requireNonNull(targetArticle));
    ar.setType(Objects.requireNonNull(ral.getType()));
    return ar;
}
Also used : Article(org.ambraproject.rhino.model.Article) ArticleRelationship(org.ambraproject.rhino.model.ArticleRelationship)

Example 25 with Article

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

the class ArticleCrudServiceImpl method serveRevisions.

@Override
public ServiceResponse<List<ArticleRevisionView>> serveRevisions(ArticleIdentifier id) {
    Article article = readArticle(id);
    List<ArticleRevision> revisions = (List<ArticleRevision>) hibernateTemplate.find("FROM ArticleRevision WHERE ingestion.article = ? ORDER BY revisionNumber", article);
    List<ArticleRevisionView> views = Lists.transform(revisions, ArticleRevisionView::getView);
    return ServiceResponse.serveView(views);
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) ArticleRevisionView(org.ambraproject.rhino.view.article.ArticleRevisionView) Article(org.ambraproject.rhino.model.Article) List(java.util.List) ArrayList(java.util.ArrayList)

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