Search in sources :

Example 6 with ModelResult

use of com.ganster.cms.web.dto.ModelResult in project Ganster-CMS by Gangster-trio.

the class WebService method getSiteModel.

public ModelResult getSiteModel(String siteUrl) {
    ModelResult result = new ModelResult();
    // ---------------------------------------default properties start----------------------------------------------//
    // get Site object
    SiteExample siteExample = new SiteExample();
    siteExample.or().andSiteUrlEqualTo(siteUrl);
    List<Site> siteList = siteService.selectByExample(siteExample);
    if (siteList.isEmpty()) {
        return null;
    }
    Site site = siteList.get(0);
    // Get 0 level categorise in this site (displayed above the homepage of the website)
    CategoryExample categoryExample = new CategoryExample();
    categoryExample.or().andCategorySiteIdEqualTo(site.getSiteId()).andCategoryLevelEqualTo(0);
    List<Category> categoryList = categoryService.selectByExample(categoryExample);
    // Each level 0 category into category tree
    List<CategoryTree> categoryTreeList = categoryList.stream().map(categoryService::toTree).collect(Collectors.toList());
    // Get a list of categories to put on the home page (with short article info)
    categoryExample.clear();
    categoryExample.or().andCategoryTypeEqualTo(CmsConst.INDEX_CATEGORY_TYPE).andCategorySiteIdEqualTo(site.getSiteId());
    List<Category> indexCategoryList = categoryService.selectByExample(categoryExample);
    // Get the list of articles to place on the homepage
    ArticleExample articleExample = new ArticleExample();
    articleExample.or().andArticleTypeEqualTo(CmsConst.INDEX_ARTICLE_TYPE).andArticleSiteIdEqualTo(site.getSiteId());
    List<Article> articleList = articleService.selectByExample(articleExample);
    // Get the home carousel article
    articleExample.clear();
    articleExample.or().andArticleTypeEqualTo(CmsConst.CAROUSEL_ARTICLE_TYPE).andArticleSiteIdEqualTo(site.getSiteId());
    List<Article> carouselList = articleService.selectByExample(articleExample);
    // The default template needs the data
    result.put("categoryTreeList", categoryTreeList).put("site", site).put("indexCategoryList", indexCategoryList).put("articleList", articleList).put("carouselList", carouselList);
    // ---------------------------------------custom properties start----------------------------------------------//
    /*
        The custom type category Need to pass to the home page
        key - type
        value - list of (category)
               map<"type",
                   list[
                       (category)->category type is "type"
                    ]
                >
        */
    categoryExample.clear();
    categoryExample.or().andCategoryInHomepageEqualTo(true).andCategorySiteIdEqualTo(site.getSiteId());
    result.getMap().putAll(categoryService.selectByExample(categoryExample).stream().collect(Collectors.groupingBy(Category::getCategoryType)));
    /*
        The custom type article Need to pass to the home page
        key - "type"
        value - list of (article->article type is "type")
              map<"type",
                  list[
                      article -> article type is "type"
                  ]
                 >
        */
    articleExample.clear();
    articleExample.or().andArticleInHomepageEqualTo(true).andArticleSiteIdEqualTo(site.getSiteId());
    result.getMap().putAll(articleService.selectByExample(articleExample).parallelStream().collect(Collectors.groupingBy(Article::getArticleType)));
    return result;
}
Also used : ModelResult(com.ganster.cms.web.dto.ModelResult)

Aggregations

ModelResult (com.ganster.cms.web.dto.ModelResult)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Article (com.ganster.cms.core.pojo.Article)1 Category (com.ganster.cms.core.pojo.Category)1 Site (com.ganster.cms.core.pojo.Site)1