use of org.summerb.microservices.articles.api.dto.Article in project summerb by skarpushin.
the class ArticlesAuthoringController method getArticle.
@RequestMapping(method = RequestMethod.GET, value = "/{articleKey}")
public String getArticle(Model model, @PathVariable("articleKey") String articleKey, Locale locale) throws NotAuthorizedException {
model.addAttribute(ATTR_ARTICLE_KEY, articleKey);
Map<Locale, Article> options = articleService.findArticleLocalizations(articleKey);
if (options.size() == 0) {
throw new RuntimeException("Article not found: " + articleKey);
}
List<ArticleVm> contents = new LinkedList<ArticleVm>();
for (Entry<Locale, Article> entry : options.entrySet()) {
ArticleVm contentPm = new ArticleVm();
contentPm.setDto(entry.getValue());
contentPm.setAttachments(new ListPm<Attachment>(Arrays.asList(articleService.findArticleAttachments(entry.getValue().getId()))));
contents.add(contentPm);
}
ArticlesVm articlesVm = new ArticlesVm(contents);
model.addAttribute(ATTR_ARTICLES, articlesVm.getMap());
model.addAttribute(ATTR_ARTICLE, contents.get(0));
return viewNameArticleAuthoring;
}
use of org.summerb.microservices.articles.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.microservices.articles.api.dto.Article in project summerb by skarpushin.
the class ArticleRendererCachingImplTest method testRenderArticle_expectNewVersionWillBeReturnedAfterEvent.
@Test
public void testRenderArticle_expectNewVersionWillBeReturnedAfterEvent() throws Exception {
ArticleRendererCachingImpl fixture = new ArticleRendererCachingImpl();
fixture.setEventBus(mock(EventBus.class));
ArticleRenderer renderer = mock(ArticleRenderer.class);
fixture.setArticleRenderer(renderer);
fixture.afterPropertiesSet();
Locale locale = new Locale("ru");
mockTest(renderer, locale);
// force cache
RenderedArticle ra3v1 = fixture.renderArticle("a3", locale);
assertEquals("t3v1", ra3v1.getTitle());
RenderedArticle ra3v2 = new RenderedArticle();
ra3v2.setId(3L);
ra3v2.setLang("ru");
ra3v2.setTitle("t3v2");
ra3v2.setArticleKey("a3");
ra3v2.setContent("c");
when(renderer.renderArticle("a3", locale)).thenReturn(ra3v2);
ra3v1 = fixture.renderArticle("a3", locale);
assertEquals("t3v1", ra3v1.getTitle());
Article a3 = new Article();
a3.setArticleKey("a3");
a3.setLang("ru");
fixture.onArticleChanged(EntityChangedEvent.updated(a3));
ra3v1 = fixture.renderArticle("a3", locale);
assertEquals("t3v2", ra3v1.getTitle());
}
use of org.summerb.microservices.articles.api.dto.Article in project summerb by skarpushin.
the class ArticleRendererCachingImplTest method testRenderArticle_expectDependentWillBeEvictedAsWell.
@Test
public void testRenderArticle_expectDependentWillBeEvictedAsWell() throws Exception {
ArticleRendererCachingImpl fixture = new ArticleRendererCachingImpl();
fixture.setEventBus(mock(EventBus.class));
ArticleRenderer renderer = mock(ArticleRenderer.class);
fixture.setArticleRenderer(renderer);
fixture.afterPropertiesSet();
Locale locale = new Locale("ru");
mockTest(renderer, locale);
// force cache
fixture.renderArticle("a1", locale);
fixture.renderArticle("a2", locale);
fixture.renderArticle("a3", locale);
RenderedArticle ra1v2 = new RenderedArticle();
ra1v2.setId(1L);
ra1v2.setLang("ru");
ra1v2.setTitle("t1v2");
ra1v2.setArticleKey("a1");
ra1v2.setContent("c");
ra1v2.setArticleReferences(Arrays.asList(2L, 3L));
when(renderer.renderArticle("a1", locale)).thenReturn(ra1v2);
Article a3 = new Article();
a3.setArticleKey("a3");
a3.setLang("ru");
fixture.onArticleChanged(EntityChangedEvent.updated(a3));
ra1v2 = fixture.renderArticle("a1", locale);
assertEquals("t1v2", ra1v2.getTitle());
}
use of org.summerb.microservices.articles.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;
}
Aggregations