Search in sources :

Example 11 with Article

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;
}
Also used : Locale(java.util.Locale) ArticlesVm(org.summerb.microservices.articles.mvc.vm.ArticlesVm) ArticleVm(org.summerb.microservices.articles.mvc.vm.ArticleVm) Article(org.summerb.microservices.articles.api.dto.Article) Attachment(org.summerb.microservices.articles.api.dto.Attachment) LinkedList(java.util.LinkedList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with Article

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;
}
Also used : Article(org.summerb.microservices.articles.api.dto.Article) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Article

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());
}
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 14 with Article

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());
}
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 15 with Article

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;
}
Also used : Article(org.summerb.microservices.articles.api.dto.Article)

Aggregations

Article (org.summerb.microservices.articles.api.dto.Article)15 Locale (java.util.Locale)6 Test (org.junit.Test)5 RenderedArticle (org.summerb.microservices.articles.api.dto.consuming.RenderedArticle)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Attachment (org.summerb.microservices.articles.api.dto.Attachment)3 EventBus (com.google.common.eventbus.EventBus)2 HashMap (java.util.HashMap)2 ArticleRenderer (org.summerb.microservices.articles.api.ArticleRenderer)2 UrlBuilderTestImpl (integr.ru.skarpushin.services.articles.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.approaches.jdbccrud.api.exceptions.GenericEntityNotFoundException)1 PageMessage (org.summerb.approaches.springmvc.model.PageMessage)1 FieldValidationException (org.summerb.approaches.validation.FieldValidationException)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 ArticleVm (org.summerb.microservices.articles.mvc.vm.ArticleVm)1