Search in sources :

Example 1 with ArticlesVm

use of org.summerb.microservices.articles.mvc.vm.ArticlesVm 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)

Aggregations

LinkedList (java.util.LinkedList)1 Locale (java.util.Locale)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 Article (org.summerb.microservices.articles.api.dto.Article)1 Attachment (org.summerb.microservices.articles.api.dto.Attachment)1 ArticleVm (org.summerb.microservices.articles.mvc.vm.ArticleVm)1 ArticlesVm (org.summerb.microservices.articles.mvc.vm.ArticlesVm)1