Search in sources :

Example 1 with ModelResult

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

the class SiteController method show.

@RequestMapping("/{siteUrl}")
public String show(@PathVariable("siteUrl") String siteUrl, Model model) {
    ModelResult result = webService.getSiteModel(siteUrl);
    if (result == null) {
        return "404";
    }
    // Add result to module
    model.addAttribute("result", result);
    Site site = (Site) result.get("site");
    // If skin = null, set default skin
    if (site.getSiteSkin() == null) {
        site.setSiteSkin(CmsConst.DEFAULT_SKIN);
    }
    // Return to the site's skin view, for example : default-site
    return site.getSiteSkin() + CmsConst.SITE_SKIN_SUFFIX;
}
Also used : Site(com.ganster.cms.core.pojo.Site) ModelResult(com.ganster.cms.web.dto.ModelResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ModelResult

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

the class WebService method getArticleModel.

public ModelResult getArticleModel(Integer id) {
    Article article = articleService.selectByPrimaryKey(id);
    ModelResult result = new ModelResult();
    if (article == null) {
        return null;
    }
    // Get article's site
    Site site = siteService.selectByPrimaryKey(article.getArticleSiteId());
    // Get article's category
    Category category = categoryService.selectByPrimaryKey(article.getArticleCategoryId());
    // Get article's tags
    List<Tag> tagList = tagService.selectByArticleId(id);
    // Get 0 level categorise in this site (displayed above the homepage of the website)
    CategoryExample categoryExample = new CategoryExample();
    categoryExample.or().andCategorySiteIdEqualTo(article.getArticleSiteId()).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());
    result.put("category", category).put("article", article).put("tagList", tagList).put("categoryTreeList", categoryTreeList).put("site", site);
    // hit add
    if (article.getArticleHit() == null) {
        article.setArticleHit(0);
    }
    article.setArticleHit(article.getArticleHit() + 1);
    articleService.updateByPrimaryKeySelective(article);
    return result;
}
Also used : ModelResult(com.ganster.cms.web.dto.ModelResult)

Example 3 with ModelResult

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

the class WebService method getCategoryModel.

public ModelResult getCategoryModel(Integer id) {
    ModelResult result = new ModelResult();
    Category category = categoryService.selectByPrimaryKey(id);
    if (category == null) {
        return null;
    }
    // ---------------------------------------default properties start----------------------------------------------//
    Site site = siteService.selectByPrimaryKey(category.getCategorySiteId());
    // Get 0 level categorise in this site (displayed above the homepage of the website)
    CategoryExample categoryExample = new CategoryExample();
    categoryExample.or().andCategorySiteIdEqualTo(category.getCategorySiteId()).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 this category's article list (without BLOBs)
    ArticleExample articleExample = new ArticleExample();
    articleExample.or().andArticleCategoryIdEqualTo(id);
    List<Article> articleList = articleService.selectByExample(articleExample);
    result.put("categoryTreeList", categoryTreeList).put("articleList", articleList).put("category", category).put("site", site);
    return result;
}
Also used : ModelResult(com.ganster.cms.web.dto.ModelResult)

Example 4 with ModelResult

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

the class ArticleController method show.

@RequestMapping("{id}")
public String show(@PathVariable("id") Integer id, Model model) {
    ModelResult result = webService.getArticleModel(id);
    if (result == null) {
        return "404";
    }
    model.addAttribute("result", result);
    Article article = (Article) result.get("article");
    // If skin = null, set default skin
    if (article.getArticleSkin() == null) {
        article.setArticleSkin(CmsConst.DEFAULT_SKIN);
    }
    // Return to the site's skin view, for example : default-article
    return article.getArticleSkin() + CmsConst.ARTICLE_SKIN_SUFFIX;
}
Also used : ModelResult(com.ganster.cms.web.dto.ModelResult) Article(com.ganster.cms.core.pojo.Article) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ModelResult

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

the class CategoryController method show.

@RequestMapping("{id}")
public String show(@PathVariable("id") Integer id, Model model) {
    ModelResult result = webService.getCategoryModel(id);
    if (result == null) {
        return "404";
    }
    // Add result to module
    model.addAttribute("result", result);
    Category category = (Category) result.get("category");
    // If skin = null, set default skin
    if (category.getCategorySkin() == null) {
        category.setCategorySkin(CmsConst.DEFAULT_SKIN);
    }
    // Return to the site's skin view, for example : default-category
    return category.getCategorySkin() + CmsConst.CATEGORY_SKIN_SUFFIX;
}
Also used : ModelResult(com.ganster.cms.web.dto.ModelResult) Category(com.ganster.cms.core.pojo.Category) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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