Search in sources :

Example 1 with ArticleCategoryAssignmentFlag

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();
    });
}
Also used : AmbraService(org.ambraproject.rhino.service.impl.AmbraService) Article(org.ambraproject.rhino.model.Article) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) TaxonomyClassificationService(org.ambraproject.rhino.service.taxonomy.TaxonomyClassificationService) ArticleCategoryAssignment(org.ambraproject.rhino.model.ArticleCategoryAssignment) WeightedTerm(org.ambraproject.rhino.service.taxonomy.WeightedTerm) ArticleCategoryAssignmentFlag(org.ambraproject.rhino.model.ArticleCategoryAssignmentFlag) List(java.util.List) ArticleRevision(org.ambraproject.rhino.model.ArticleRevision) Category(org.ambraproject.rhino.model.Category) Document(org.w3c.dom.Document) LocalDate(java.time.LocalDate) TaxonomyService(org.ambraproject.rhino.service.taxonomy.TaxonomyService) Query(org.hibernate.Query) Optional(java.util.Optional) Query(org.hibernate.Query) List(java.util.List)

Example 2 with ArticleCategoryAssignmentFlag

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);
}
Also used : ArticleCategoryAssignmentFlag(org.ambraproject.rhino.model.ArticleCategoryAssignmentFlag)

Aggregations

ArticleCategoryAssignmentFlag (org.ambraproject.rhino.model.ArticleCategoryAssignmentFlag)2 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 Article (org.ambraproject.rhino.model.Article)1 ArticleCategoryAssignment (org.ambraproject.rhino.model.ArticleCategoryAssignment)1 ArticleRevision (org.ambraproject.rhino.model.ArticleRevision)1 Category (org.ambraproject.rhino.model.Category)1 AmbraService (org.ambraproject.rhino.service.impl.AmbraService)1 TaxonomyClassificationService (org.ambraproject.rhino.service.taxonomy.TaxonomyClassificationService)1 TaxonomyService (org.ambraproject.rhino.service.taxonomy.TaxonomyService)1 WeightedTerm (org.ambraproject.rhino.service.taxonomy.WeightedTerm)1 Query (org.hibernate.Query)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Document (org.w3c.dom.Document)1