use of org.ambraproject.rhino.model.ArticleCategoryAssignmentFlag in project rhino by PLOS.
the class TaxonomyServiceImpl method getArticleCategoryAssignmentFlags.
private List<ArticleCategoryAssignmentFlag> getArticleCategoryAssignmentFlags(Article article, Category category, Optional<Long> userProfileId) {
return hibernateTemplate.execute(session -> {
Query query = userProfileId.map(userProfileIdValue -> session.createQuery("" + "FROM ArticleCategoryAssignmentFlag " + "WHERE article = :article AND category = :category AND userProfileId = :userProfileId").setParameter("userProfileId", userProfileIdValue)).orElseGet(() -> session.createQuery("" + "FROM ArticleCategoryAssignmentFlag " + "WHERE article = :article AND category = :category AND userProfileId IS NULL"));
query.setParameter("article", article);
query.setParameter("category", category);
return (List<ArticleCategoryAssignmentFlag>) query.list();
});
}
use of org.ambraproject.rhino.model.ArticleCategoryAssignmentFlag in project rhino by PLOS.
the class TaxonomyServiceImpl method flagArticleCategory.
@Override
public void flagArticleCategory(Article article, Category category, Optional<Long> userProfileId) throws IOException {
if (userProfileId.isPresent()) {
List<ArticleCategoryAssignmentFlag> flags = getArticleCategoryAssignmentFlags(article, category, userProfileId);
if (!flags.isEmpty()) {
// The system already has a flag for this assignment from this user. No need to create a redundant one.
return;
}
}
ArticleCategoryAssignmentFlag flag = new ArticleCategoryAssignmentFlag();
flag.setArticle(article);
flag.setCategory(category);
flag.setUserProfileId(userProfileId.orElse(null));
hibernateTemplate.save(flag);
}
Aggregations