Search in sources :

Example 1 with ArticlesVm

use of org.summerb.webappboilerplate.articles.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(attachmentService.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.webappboilerplate.articles.vm.ArticlesVm) ArticleVm(org.summerb.webappboilerplate.articles.vm.ArticleVm) Article(org.summerb.minicms.api.dto.Article) Attachment(org.summerb.minicms.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.minicms.api.dto.Article)1 Attachment (org.summerb.minicms.api.dto.Attachment)1 ArticleVm (org.summerb.webappboilerplate.articles.vm.ArticleVm)1 ArticlesVm (org.summerb.webappboilerplate.articles.vm.ArticlesVm)1