use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsController method updatePost.
@RequestMapping(value = "/update", method = POST)
public String updatePost(@Valid PostDTO postDTO, BindingResult result, Model model, RedirectAttributes attributes, HttpServletRequest request) throws PostNotFoundException {
if (result.hasErrors()) {
model.addAttribute("postDTO", postDTO);
model.addAllAttributes(getPostLinkAttributes(request, postDTO.getPostType()));
return ADMIN_POSTLINK_UPDATE_VIEW;
} else {
postDTO.setPostContent(cleanContentTailHtml(postDTO.getPostContent()));
Post post = postService.update(postDTO);
PostDoc postDoc = postDocService.getPostDocByPostId(post.getPostId());
boolean postIsIndexed = postDoc != null;
if (post.getIsPublished()) {
post.setPostMeta(jsoupService.updatePostMeta(postDTO));
if (applicationSettings.getSolrEnabled()) {
if (postIsIndexed)
postDocService.updatePostDocument(post);
else
postDocService.addToIndex(post);
}
fmService.createPostAtoZs();
} else {
// remove postDocument from Solr Index if previously marked "Published", now marked "Draft"
if (postIsIndexed)
if (applicationSettings.getSolrEnabled()) {
postDocService.removeFromIndex(postDoc);
}
}
webUI.addFeedbackMessage(attributes, FEEDBACK_POST_UPDATED);
return "redirect:/admin/posts";
}
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsController method createLinkPost.
// endregion
// region Add Post POST
@RequestMapping(value = "/add/link", method = POST)
public String createLinkPost(@Valid PostDTO postDTO, BindingResult result, CurrentUser currentUser, RedirectAttributes attributes, Model model, HttpServletRequest request) throws DuplicatePostNameException {
PagePreviewDTO pagePreview = (PagePreviewDTO) WebUtils.getSessionAttribute(request, "pagePreview");
model.addAttribute("postheader", webUI.getMessage(ADD_LINK_HEADER));
model.addAttribute("postFormType", "link");
if (!isDuplicatePost(postDTO, null)) {
if (result.hasErrors()) {
model.addAttribute("hasLink", true);
model.addAttribute("hasCarousel", true);
model.addAttribute("pagePreview", pagePreview);
if (result.hasFieldErrors("postTitle")) {
postDTO.setPostTitle(pagePreview.getTitle());
}
model.addAttribute("postDTO", postDTO);
return ADMIN_LINK_ADD_VIEW;
} else {
if (postDTO.getHasImages()) {
if (postDTO.getDisplayType() != PostDisplayType.LINK) {
postDTO.setPostImage(pagePreview.getImages().get(postDTO.getImageIndex()).src);
} else
postDTO.setPostImage(null);
}
postDTO.setPostSource(PostUtils.createPostSource(postDTO.getPostLink()));
postDTO.setPostName(PostUtils.createSlug(postDTO.getPostTitle()));
postDTO.setUserId(currentUser.getId());
postDTO.setPostContent(cleanContentTailHtml(postDTO.getPostContent()));
request.setAttribute("postTitle", postDTO.getPostTitle());
Post post = postService.add(postDTO);
postDTO.setPostId(post.getPostId());
post.setPostMeta(jsoupService.createPostMeta(postDTO));
// All links are saved as PUBLISHED so no _isPublished_ status check on new Links
if (applicationSettings.getSolrEnabled())
postDocService.addToIndex(post);
// Links are included in Posts A-to-Z Listing
fmService.createPostAtoZs();
webUI.addFeedbackMessage(attributes, FEEDBACK_POST_LINK_ADDED);
return "redirect:/admin/posts";
}
} else {
result.reject("global.error.post.name.exists", new Object[] { postDTO.getPostTitle() }, "post name exists");
model.addAttribute("hasLink", true);
model.addAttribute("hasCarousel", true);
model.addAttribute("pagePreview", pagePreview);
return ADMIN_LINK_ADD_VIEW;
}
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class GeneralController method homeBannerDisplay.
@RequestMapping(value = "/dev/banner", method = GET)
public String homeBannerDisplay(Model model, @RequestParam(value = "id") long siteImageId) {
String springVersion = webUI.parameterizedMessage("home.spring.version", SpringBootVersion.getVersion());
model.addAttribute("springVersion", springVersion);
SiteImage siteImage = siteService.getHomeBanner(siteImageId);
model.addAttribute("siteImage", siteImage);
Slice<Post> posts = postService.getPublishedPosts(0, 10);
if (posts.getContent().size() > 0)
model.addAttribute("posts", posts);
return HOME_VIEW;
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsController method reindexSolrPosts.
@RequestMapping(value = "/solr/reindex", params = "reindex", method = GET)
public ModelAndView reindexSolrPosts() {
ModelAndView mav = new ModelAndView();
List<Post> posts = postService.getAllPublishedPosts();
int postDocCount = posts.size();
long lStartTime = new Date().getTime();
postDocService.reindexPosts(posts);
long lEndTime = new Date().getTime();
long duration = lEndTime - lStartTime;
String totalTime = String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration), TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)));
String reindexMessage = webUI.getMessage(MESSAGE_ADMIN_SOLR_REINDEX_COMPLETE, postDocCount, totalTime);
mav.addObject("reindexMessage", reindexMessage);
mav.addObject("hasPostDocCount", true);
mav.setViewName(ADMIN_POSTS_REINDEX_VIEW);
return mav;
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class FmServiceTests method rssMultiPhotoPostDisplayTypeContentTest.
@Test
public void rssMultiPhotoPostDisplayTypeContentTest() throws PostNotFoundException {
// H2 POST 12L 'multiphoto-post' MULTIPHOTO_POST PostDisplayType
Post post = postService.getPost("multiphoto-post");
String result = fmService.createRssPostContent(post);
assertThat(result, containsString("src=\"http://"));
}
Aggregations