private void handleError(BlogContext context, BlogPolicy blog, String errorMessageKey) { context.addErrorShowBlogEdit(errorMessageKey); try { if (blog != null) { context.getPolicyCMServer().abortContent(blog); } } catch (CMException e) { LOG.log(Level.WARNING, "Error while updating blog content.", e); } }
public boolean execute(Context context) { BlogContext blogContext = (BlogContext) context; RenderRequest renderRequest = blogContext.getRenderRequest(); PolicyCMServer cmServer = blogContext.getPolicyCMServer(); ContentId blogId = blogContext.getBlogContentId(); BlogForm blogForm = populateBlogForm(renderRequest); ModelWrite localModel = blogContext.getTopModel().getLocal(); localModel.setAttribute("blogForm", blogForm); if (!(blogFormValidator.validate(blogContext, blogForm))) { return false; } BlogPolicy blog = null; try { blog = (BlogPolicy) cmServer.createContentVersion(blogId.getLatestCommittedVersionId()); blog.setName(blogForm.getBlogName()); blog.setPathSegmentString(blogForm.getBlogAddress()); blog.setDescription(blogForm.getBlogDescription()); cmServer.commitContent(blog); blogContext.getLocalModel().setAttribute("content", blog); } catch (UrlPathSegmentAlreadyExistsException e) { handleError(blogContext, blog, RenderControllerBlog.WEB_ALIAS_EXISTS_ERROR); } catch (InvalidUrlPathSegmentException e) { handleError(blogContext, blog, RenderControllerBlog.FIELD_REQUIRED_BLOG_ADDRESS); } catch (CMException e) { LOG.log(Level.WARNING, "Error while updating blog content.", e); handleError(blogContext, blog, RenderControllerBlog.INTERNAL_SERVER_ERROR); } return true; }