use of org.summerb.webappboilerplate.model.PageMessage in project summerb by skarpushin.
the class ArticleController method get.
@RequestMapping(method = RequestMethod.GET, value = ArticleAbsoluteUrlBuilderImpl.DEFAULT_PATH_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;
}
use of org.summerb.webappboilerplate.model.PageMessage in project summerb by skarpushin.
the class ControllerExceptionHandlerStrategyLegacyImpl method buildHtmlError.
protected ModelAndView buildHtmlError(Throwable ex) {
if (securityContextResolver != null && (ex instanceof AccessDeniedException && !securityContextResolver.hasRole(Roles.ROLE_USER))) {
throw new IllegalArgumentException("Exception will not be handled by default exception handler: " + ex);
}
log.error("Exception occured", ex);
ModelAndView ret = new ModelAndView(Views.ERROR_UNEXPECTED_CLARIFIED);
String msg = exceptionTranslator.buildUserMessage(ex, LocaleContextHolder.getLocale());
if (!StringUtils.hasText(msg)) {
msg = ExceptionUtils.getAllMessagesRaw(ex);
}
ControllerBase.addPageMessage(ret.getModel(), new PageMessage(msg, MessageSeverity.Danger));
ret.getModel().put(ControllerBase.ATTR_EXCEPTION, msg);
ret.getModel().put(ControllerBase.ATTR_EXCEPTION_STACKTRACE, ExceptionUtils.getThrowableStackTraceAsString(ex));
return ret;
}
use of org.summerb.webappboilerplate.model.PageMessage in project summerb by skarpushin.
the class ArticlesAuthoringController method createAttachment.
// NOTE: File upload example:
// http://www.ioncannon.net/programming/975/spring-3-file-upload-example/
@RequestMapping(method = RequestMethod.POST, value = "/{articleId}/addAttachment")
public String createAttachment(@ModelAttribute(ATTR_ARTICLE_ATTACHMENT) ArticleAttachmentVm articleAttachmentVm, Model model, @PathVariable("articleId") long articleId) throws Exception {
try {
Preconditions.checkArgument(articleAttachmentVm.getFile() != null && articleAttachmentVm.getFile().getFileItem() != null, "File required");
Article article = articleService.findById(articleId);
Preconditions.checkArgument(article != null, "Article not found");
Attachment att = articleAttachmentVm.getAttachment();
att.setArticleId(articleId);
FileItem fileItem = articleAttachmentVm.getFile().getFileItem();
att.setSize(fileItem.getSize());
String fileName = fileItem.getName();
att.setName(fileName);
att.setContents(articleAttachmentVm.getFile().getInputStream());
attachmentService.create(att);
return Views.redirect(String.format("article-authoring/%s", article.getArticleKey()));
} catch (Throwable t) {
log.error("Failed to create attachment", t);
String msg = exceptionTranslator.buildUserMessage(t, CurrentRequestUtils.getLocale());
addPageMessage(model.asMap(), new PageMessage(msg, MessageSeverity.Danger));
// TBD: Navigate to article authoring instead!
return viewNameArticleAuthoring;
}
}
Aggregations