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);
}
}
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));
}
}
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;
}
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;
}
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);
}
}
Aggregations