Search in sources :

Example 1 with Article

use of org.summerb.minicms.api.dto.Article in project summerb by skarpushin.

the class ArticleRendererImpl method renderArticle.

@Override
public RenderedArticle renderArticle(String key, Locale locale) {
    Preconditions.checkArgument(StringUtils.hasText(key));
    Preconditions.checkArgument(locale != null);
    try {
        Article article = articleService.findArticleByKeyAndLocale(key, locale);
        if (article == null) {
            throw new RuntimeException("Article not found: " + key + ", locale: " + locale);
        }
        RenderedArticle renderedArticle = buildRenderedArticleTemplate(article);
        ArticleRenderingContext articleRenderingContext = new ArticleRenderingContext(locale, renderedArticle, articleService, attachmentService, articleAbsoluteUrlBuilder);
        StringTemplate annotationTemplate = stringTemplateCompiler.compile(article.getAnnotation());
        renderedArticle.setAnnotation(annotationTemplate.applyTo(articleRenderingContext));
        StringTemplate contentTemplate = stringTemplateCompiler.compile(article.getContent());
        renderedArticle.setContent(contentTemplate.applyTo(articleRenderingContext));
        return renderedArticle;
    } catch (Throwable t) {
        throw new RuntimeException("Failed to render article", t);
    }
}
Also used : Article(org.summerb.minicms.api.dto.Article) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle) StringTemplate(org.summerb.stringtemplate.api.StringTemplate) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle)

Example 2 with Article

use of org.summerb.minicms.api.dto.Article in project summerb by skarpushin.

the class ArticleServiceImplTest method testCreateArticleContent_testDataTruncationError.

@Test
public void testCreateArticleContent_testDataTruncationError() throws Exception {
    Article a = buildTestDto();
    a.setArticleKey(generateLongString(Article.FN_KEY_SIZE, "Z"));
    a.setLang("ZZ");
    a.setTitle(generateLongString(Article.FN_TITLE_SIZE, "Ф"));
    a.setAnnotation(generateLongString(Article.FN_ANNOTATION_SIZE, "Ф"));
    a.setContent(generateLongString(Article.FN_ANNOTATION_SIZE, "Ф"));
    a.setArticleGroup(generateLongString(Article.FN_GROUP_SIZE, "Z"));
    articleService.create(a);
    // Update data with wrong length text
    try {
        a = buildTestDto();
        a.setArticleKey(generateLongString(Article.FN_KEY_SIZE + 1, "ф"));
        a.setLang("ZZZ");
        a.setTitle(generateLongString(Article.FN_TITLE_SIZE + 1, "Ф"));
        a.setAnnotation(generateLongString(Article.FN_ANNOTATION_SIZE + 1, "ф"));
        a.setContent(generateLongString(Article.FN_ANNOTATION_SIZE + 1, "ф"));
        a.setArticleGroup(generateLongString(Article.FN_GROUP_SIZE + 1, "Z"));
        articleService.create(a);
        fail("FVE expected");
    } catch (FieldValidationException fve) {
        assertEquals(5, fve.getErrors().size());
        assertNotNull(fve.findErrorOfTypeForField(DataTooLongValidationError.class, Article.FN_KEY));
        assertNotNull(fve.findErrorOfTypeForField(DataTooLongValidationError.class, Article.FN_LANG));
        assertNotNull(fve.findErrorOfTypeForField(DataTooLongValidationError.class, Article.FN_TITLE));
        assertNotNull(fve.findErrorOfTypeForField(DataTooLongValidationError.class, Article.FN_ANNOTATION));
        assertNotNull(fve.findErrorOfTypeForField(DataTooLongValidationError.class, Article.FN_GROUP));
    }
}
Also used : FieldValidationException(org.summerb.validation.FieldValidationException) Article(org.summerb.minicms.api.dto.Article) Test(org.junit.Test)

Example 3 with Article

use of org.summerb.minicms.api.dto.Article in project summerb by skarpushin.

the class ArticleServiceImplTest method buildTestDto.

private Article buildTestDto() {
    Article a = new Article();
    a.setArticleKey(AKEY);
    a.setTitle("title1");
    a.setAnnotation("ann");
    a.setContent("asdasd");
    a.setArticleGroup("somegroup");
    a.setLang("ru");
    return a;
}
Also used : Article(org.summerb.minicms.api.dto.Article)

Example 4 with Article

use of org.summerb.minicms.api.dto.Article in project summerb by skarpushin.

the class ArticlesAuthoringController method listArticles.

@RequestMapping(method = RequestMethod.GET, value = "/")
public String listArticles(Model model, Locale locale) throws NotAuthorizedException {
    PaginatedList<Article> articles = articleService.findArticles(PagerParams.ALL, locale);
    model.addAttribute(ATTR_ARTICLES, articles);
    model.addAttribute(ATTR_ARTICLE, new Article());
    return viewNameArticlesAuthoringList;
}
Also used : Article(org.summerb.minicms.api.dto.Article) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Article

use of org.summerb.minicms.api.dto.Article in project summerb by skarpushin.

the class ArticlesAuthoringController method updateArticle.

@RequestMapping(method = RequestMethod.POST, value = "/{id}")
@ResponseBody
public Map<String, ? extends Object> updateArticle(@RequestBody Article dto, @PathVariable("id") long id, HttpServletResponse response) {
    try {
        Article currentVersion = articleService.findById(id);
        currentVersion.setTitle(dto.getTitle());
        currentVersion.setAnnotation(dto.getAnnotation());
        currentVersion.setContent(dto.getContent());
        Article newVersion = articleService.update(currentVersion);
        // ret
        Map<String, Object> ret = new HashMap<String, Object>();
        ret.put(ATTR_ARTICLE, newVersion);
        return ret;
    } catch (Throwable t) {
        log.error("Failed to update article content", t);
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        String msg = exceptionTranslator.buildUserMessage(t, CurrentRequestUtils.getLocale());
        return Collections.singletonMap(ATTR_ERROR, msg);
    }
}
Also used : HashMap(java.util.HashMap) Article(org.summerb.minicms.api.dto.Article) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Article (org.summerb.minicms.api.dto.Article)15 Locale (java.util.Locale)6 Test (org.junit.Test)5 RenderedArticle (org.summerb.minicms.api.dto.consuming.RenderedArticle)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Attachment (org.summerb.minicms.api.dto.Attachment)3 EventBus (com.google.common.eventbus.EventBus)2 HashMap (java.util.HashMap)2 ArticleRenderer (org.summerb.minicms.api.ArticleRenderer)2 UrlBuilderTestImpl (integr.org.summerb.minicms.impl.UrlBuilderTestImpl)1 LinkedList (java.util.LinkedList)1 FileItem (org.apache.commons.fileupload.FileItem)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 GenericEntityNotFoundException (org.summerb.easycrud.api.exceptions.GenericEntityNotFoundException)1 EmailMessageBuilderImpl (org.summerb.email.impl.EmailMessageBuilderImpl)1 LocaleAwareEmailMessageBuilderImpl (org.summerb.email.impl.LocaleAwareEmailMessageBuilderImpl)1 ArticleAbsoluteUrlBuilder (org.summerb.minicms.api.ArticleAbsoluteUrlBuilder)1 ArticleService (org.summerb.minicms.api.ArticleService)1 AttachmentService (org.summerb.minicms.api.AttachmentService)1 ArticleRendererImpl (org.summerb.minicms.impl.ArticleRendererImpl)1