Search in sources :

Example 1 with Article

use of com.ganster.cms.core.pojo.Article in project Ganster-CMS by Gangster-trio.

the class ArticleServiceTest method PageHelperTest.

@Test
@Transactional
public void PageHelperTest() {
    final String TEST_AUTHOR = "PageHelperTest.-@#$%^&*&^%";
    // insert Data
    List<Article> articles = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        Article article = new Article();
        article.setArticleAuthor(TEST_AUTHOR);
        articles.add(article);
    }
    for (Article article : articles) {
        articleService.insert(article);
    }
    ArticleExample articleExample = new ArticleExample();
    articleExample.or().andArticleAuthorEqualTo(TEST_AUTHOR);
    PageHelper.startPage(1, 2);
    articles = articleService.selectByExample(articleExample);
    PageInfo<Article> pageInfo = new PageInfo<>(articles);
    // PageInfo page = PageHelper.startPage(1,5).doSelectPageInfo(() -> articleService.selectByExample(articleExample));
    LOGGER.info(pageInfo.toString());
    for (Article article : articles) {
        LOGGER.info(article.toString());
    }
    Assert.assertEquals(articles.size(), 2);
// articleService.deleteByExample(articleExample);
}
Also used : PageInfo(com.github.pagehelper.PageInfo) Article(com.ganster.cms.core.pojo.Article) ArrayList(java.util.ArrayList) ArticleExample(com.ganster.cms.core.pojo.ArticleExample) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Article

use of com.ganster.cms.core.pojo.Article in project Ganster-CMS by Gangster-trio.

the class ArticleDTO method toArticle.

// 不可以向下转型
public Article toArticle() {
    Article article = new Article();
    article.setArticleTitle(getArticleTitle());
    article.setArticleSkin(getArticleSkin());
    article.setArticleAuthor(getArticleAuthor());
    article.setArticleCreateTime(getArticleCreateTime());
    article.setArticleSiteId(getArticleSiteId());
    article.setArticleUpdateTime(getArticleUpdateTime());
    article.setArticleHit(getArticleHit());
    article.setArticleCategoryId(getArticleCategoryId());
    article.setArticleContent(getArticleContent());
    article.setArticleDesc(getArticleDesc());
    article.setArticleInHomepage(getArticleInHomepage());
    article.setArticleOrder(getArticleOrder());
    article.setArticleStatus(getArticleStatus());
    article.setArticleType(getArticleType());
    article.setArticleThumb(getArticleThumb());
    article.setArticleUrl(getArticleUrl());
    return article;
}
Also used : Article(com.ganster.cms.core.pojo.Article)

Example 3 with Article

use of com.ganster.cms.core.pojo.Article in project Ganster-CMS by Gangster-trio.

the class ArticleServiceTest method generatorAutoGetKeyTest.

@Test
@Transactional
public void generatorAutoGetKeyTest() {
    Article article = new Article();
    article.setArticleAuthor("generatorAutoGetKeyTest");
    articleService.insert(article);
    LOGGER.info(article.toString());
    Assert.assertNotNull(article.getArticleId());
    Assert.assertNotEquals(article.getArticleId().intValue(), 0);
}
Also used : Article(com.ganster.cms.core.pojo.Article) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Article

use of com.ganster.cms.core.pojo.Article 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 Article

use of com.ganster.cms.core.pojo.Article in project Ganster-CMS by Gangster-trio.

the class ArticleDirective method execute.

@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException {
    Integer id = DirectiveUtil.getInteger(PARAM_ID, params);
    Boolean blob = DirectiveUtil.getBoolean(PARAM_BLOB, params);
    if (blob == null) {
        blob = false;
    }
    if (id == null) {
        throw new TemplateException("Must special id", env);
    }
    Article article = null;
    ArticleExample example = new ArticleExample();
    example.or().andArticleIdEqualTo(id);
    if (blob) {
        List<Article> articleList = articleService.selectByExampleWithBLOBs(example);
        if (!articleList.isEmpty()) {
            article = articleList.get(0);
        }
    } else {
        List<Article> articles = articleService.selectByExample(example);
        if (!articles.isEmpty()) {
            article = articles.get(0);
        }
    }
    DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.getVersion());
    env.setVariable(DirectiveUtil.getRetName(PARAM_RET, params, PARAM_RET), builder.build().wrap(article));
}
Also used : Article(com.ganster.cms.core.pojo.Article) ArticleExample(com.ganster.cms.core.pojo.ArticleExample)

Aggregations

Article (com.ganster.cms.core.pojo.Article)5 ArticleExample (com.ganster.cms.core.pojo.ArticleExample)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ModelResult (com.ganster.cms.web.dto.ModelResult)1 PageInfo (com.github.pagehelper.PageInfo)1 ArrayList (java.util.ArrayList)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1