Search in sources :

Example 6 with RenderedArticle

use of org.summerb.microservices.articles.api.dto.consuming.RenderedArticle in project summerb by skarpushin.

the class ArticleRendererCachingImpl method renderArticle.

@Override
public RenderedArticle renderArticle(String articleKey, Locale locale) {
    Preconditions.checkArgument(StringUtils.hasText(articleKey));
    Preconditions.checkArgument(locale != null);
    ArticleCacheKey cacheKey = new ArticleCacheKey(articleKey, locale);
    RenderedArticle ret = cache.getUnchecked(cacheKey);
    // DeepCopy.copy(ret);
    return ret;
}
Also used : RenderedArticle(org.summerb.microservices.articles.api.dto.consuming.RenderedArticle)

Example 7 with RenderedArticle

use of org.summerb.microservices.articles.api.dto.consuming.RenderedArticle in project summerb by skarpushin.

the class ArticleController method get.

@RequestMapping(method = RequestMethod.GET, value = "/articles/{articleKey}")
public String get(Model model, @PathVariable("articleKey") String articleKey, HttpServletResponse respons, Locale locale) {
    try {
        RenderedArticle article = articleRenderer.renderArticle(articleKey, locale);
        model.addAttribute(ATTR_ARTICLE, article);
    } catch (Throwable t) {
        log.debug("Failed to get article", t);
        String msg = exceptionTranslator.buildUserMessage(t, CurrentRequestUtils.getLocale());
        addPageMessage(model.asMap(), new PageMessage(msg, MessageSeverity.Danger));
    }
    return viewNameArticle;
}
Also used : PageMessage(org.summerb.approaches.springmvc.model.PageMessage) RenderedArticle(org.summerb.microservices.articles.api.dto.consuming.RenderedArticle) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with RenderedArticle

use of org.summerb.microservices.articles.api.dto.consuming.RenderedArticle 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());
}
Also used : Locale(java.util.Locale) ArticleRenderer(org.summerb.microservices.articles.api.ArticleRenderer) RenderedArticle(org.summerb.microservices.articles.api.dto.consuming.RenderedArticle) Article(org.summerb.microservices.articles.api.dto.Article) EventBus(com.google.common.eventbus.EventBus) RenderedArticle(org.summerb.microservices.articles.api.dto.consuming.RenderedArticle) Test(org.junit.Test)

Example 9 with RenderedArticle

use of org.summerb.microservices.articles.api.dto.consuming.RenderedArticle 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());
}
Also used : Locale(java.util.Locale) ArticleRenderer(org.summerb.microservices.articles.api.ArticleRenderer) RenderedArticle(org.summerb.microservices.articles.api.dto.consuming.RenderedArticle) Article(org.summerb.microservices.articles.api.dto.Article) EventBus(com.google.common.eventbus.EventBus) RenderedArticle(org.summerb.microservices.articles.api.dto.consuming.RenderedArticle) Test(org.junit.Test)

Aggregations

RenderedArticle (org.summerb.microservices.articles.api.dto.consuming.RenderedArticle)9 Locale (java.util.Locale)4 Test (org.junit.Test)4 Article (org.summerb.microservices.articles.api.dto.Article)4 EventBus (com.google.common.eventbus.EventBus)3 ArticleRenderer (org.summerb.microservices.articles.api.ArticleRenderer)3 Attachment (org.summerb.microservices.articles.api.dto.Attachment)2 UrlBuilderTestImpl (integr.ru.skarpushin.services.articles.impl.UrlBuilderTestImpl)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 PageMessage (org.summerb.approaches.springmvc.model.PageMessage)1 ArticleAbsoluteUrlBuilder (org.summerb.microservices.articles.api.ArticleAbsoluteUrlBuilder)1 ArticleService (org.summerb.microservices.articles.api.ArticleService)1 ArticleRendererImpl (org.summerb.microservices.articles.impl.ArticleRendererImpl)1 StringTemplate (org.summerb.utils.stringtemplate.api.StringTemplate)1 StringTemplateCompilerlImpl (org.summerb.utils.stringtemplate.impl.StringTemplateCompilerlImpl)1