Search in sources :

Example 1 with Article

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

the class ArticleCrudController method flagArticleCategory.

@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/articles/{doi}/categories", params = { "flag" }, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> flagArticleCategory(@PathVariable("doi") String articleDoi, @RequestParam(value = "categoryTerm", required = true) String categoryTerm, @RequestParam(value = "userId", required = false) String userId, @RequestParam(value = "flag", required = true) String action) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
    Article article = articleCrudService.readArticle(articleId);
    Optional<Long> userIdObj = Optional.ofNullable(userId).map(Long::parseLong);
    Collection<Category> categories = taxonomyService.getArticleCategoriesWithTerm(article, categoryTerm);
    switch(action) {
        case "add":
            for (Category category : categories) {
                taxonomyService.flagArticleCategory(article, category, userIdObj);
            }
            break;
        case "remove":
            for (Category category : categories) {
                taxonomyService.deflagArticleCategory(article, category, userIdObj);
            }
            break;
        default:
            throw new RestClientException("action must be 'add' or 'remove'", HttpStatus.BAD_REQUEST);
    }
    // ajax call expects returned data so provide an empty map for the body
    return ImmutableMap.of();
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Category(org.ambraproject.rhino.model.Category) Article(org.ambraproject.rhino.model.Article) RestClientException(org.ambraproject.rhino.rest.RestClientException) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with Article

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

the class ArticleCrudController method getCommentCount.

// TODO: Get rid of this?
@Transactional(readOnly = true)
@RequestMapping(value = "/articles/{doi:.+}/comments", method = RequestMethod.GET, params = "count")
public ResponseEntity<?> getCommentCount(@PathVariable("doi") String doi) throws IOException {
    ArticleIdentifier id = ArticleIdentifier.create(DoiEscaping.unescape(doi));
    Article article = articleCrudService.readArticle(id);
    return commentCrudService.getCommentCount(article).asJsonResponse(entityGson);
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Article(org.ambraproject.rhino.model.Article) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Article

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

the class ArticleCrudServiceImpl method refreshArticleRelationships.

@Override
public void refreshArticleRelationships(ArticleRevision sourceArticleRev) {
    ArticleXml sourceArticleXml = new ArticleXml(getManuscriptXml(sourceArticleRev.getIngestion()));
    Article sourceArticle = sourceArticleRev.getIngestion().getArticle();
    List<RelatedArticleLink> xmlRelationships = sourceArticleXml.parseRelatedArticles();
    List<ArticleRelationship> dbRelationships = getRelationshipsFrom(ArticleIdentifier.create(sourceArticle.getDoi()));
    dbRelationships.forEach(ar -> hibernateTemplate.delete(ar));
    xmlRelationships.forEach(ar -> {
        getArticle(ar.getArticleId()).ifPresent((Article relatedArticle) -> {
            hibernateTemplate.save(fromRelatedArticleLink(sourceArticle, ar));
            getLatestRevision(relatedArticle).ifPresent((ArticleRevision relatedArticleRev) -> {
                ArticleXml relatedArticleXml = new ArticleXml(getManuscriptXml(relatedArticleRev.getIngestion()));
                Set<ArticleRelationship> inboundDbRelationships = getRelationshipsTo(ArticleIdentifier.create(sourceArticle.getDoi())).stream().filter(dbAr -> dbAr.getSourceArticle().equals(relatedArticle)).collect(Collectors.toSet());
                relatedArticleXml.parseRelatedArticles().stream().filter(ral -> ral.getArticleId().getDoiName().equals(sourceArticle.getDoi())).map(ral -> fromRelatedArticleLink(relatedArticle, ral)).filter(relatedAr -> !inboundDbRelationships.contains(relatedAr)).forEach(relatedAr -> hibernateTemplate.save(relatedAr));
            });
        });
    });
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) 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) ArticleXml(org.ambraproject.rhino.content.xml.ArticleXml) Article(org.ambraproject.rhino.model.Article) RelatedArticleLink(org.ambraproject.rhino.model.article.RelatedArticleLink) ArticleRelationship(org.ambraproject.rhino.model.ArticleRelationship)

Example 4 with Article

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

the class ArticleRevisionWriteServiceImpl method deleteRevision.

@Override
public void deleteRevision(ArticleRevisionIdentifier revisionId) {
    ArticleRevision revision = articleCrudService.readRevision(revisionId);
    Article article = revision.getIngestion().getArticle();
    ArticleRevision latestRevision = articleCrudService.getLatestRevision(article).orElseThrow(// should be guaranteed to exist because at least one revision exists
    RuntimeException::new);
    boolean deletingLatest = latestRevision.equals(revision);
    hibernateTemplate.delete(revision);
    if (deletingLatest) {
        articleCrudService.getLatestRevision(article).ifPresent(this::refreshForLatestRevision);
    // else, we deleted the only revision
    }
}
Also used : ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Article(org.ambraproject.rhino.model.Article)

Example 5 with Article

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

the class ArticleListCrudServiceImpl method buildMissingArticleMessage.

private static String buildMissingArticleMessage(Collection<Article> foundArticles, Collection<String> requestedArticleKeys) {
    ImmutableSet.Builder<String> foundArticleKeys = ImmutableSet.builder();
    for (Article foundArticle : foundArticles) {
        foundArticleKeys.add(foundArticle.getDoi());
    }
    Collection<String> missingKeys = Sets.difference(ImmutableSet.copyOf(requestedArticleKeys), foundArticleKeys.build());
    // coerce to a type that Gson can handle
    missingKeys = new ArrayList<>(missingKeys);
    return "Articles not found with DOIs: " + new Gson().toJson(missingKeys);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Article(org.ambraproject.rhino.model.Article) Gson(com.google.gson.Gson)

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