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;
}
Aggregations