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