use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class PostsRestController method populateMoreLikeThisStream.
private String populateMoreLikeThisStream(List<PostDoc> postDocs) {
StringBuilder result = new StringBuilder(StringUtils.EMPTY);
List<Post> posts = postDocService.getMoreLikeThisPostsFromPostDocs(postDocs);
if (posts != null) {
for (Post post : posts) {
result.append(fmService.createPostHtml(post, "mlt"));
}
} else
result = new StringBuilder(fmService.getNoMoreLikeThisMessage());
return result.toString();
}
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 AdminPostsController method updatePost.
// endregion
// region Update Posts GET POST
@RequestMapping(value = "/update/{postId}", method = GET)
public String updatePost(@PathVariable("postId") Long postId, Model model, HttpServletRequest request) throws PostNotFoundException {
Post post = postService.getPostById(postId);
String postType = StringUtils.capitalize(post.getPostType().name().toLowerCase());
String pageTitle = webUI.getMessage(MESSAGE_ADMIN_UPDATE_POSTLINK_TITLE, postType);
String pageHeading = webUI.getMessage(MESSAGE_ADMIN_UPDATE_POSTLINK_HEADING, postType);
PostDTO postDTO = getUpdatedPostDTO(post);
if (post.getPostType() == PostType.LINK) {
postDTO.setHasImages(post.getPostImage() != null);
postDTO.setPostImage(post.getPostImage());
if (postDTO.getHasImages()) {
model.addAttribute("hasLinkImage", true);
}
}
model.addAttribute("postName", post.getPostName());
model.addAttribute("postDTO", postDTO);
model.addAttribute("pageTitle", pageTitle);
model.addAttribute("pageHeading", pageHeading);
model.addAttribute("categories", postService.getAdminSelectionCategories());
model.addAllAttributes(getPostLinkAttributes(request, post.getPostType()));
return ADMIN_POSTLINK_UPDATE_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 AdminPostsController method isDuplicatePost.
private Boolean isDuplicatePost(PostDTO postDTO, Post sessionPost) {
Boolean isDuplicate = false;
if (StringUtils.isNotEmpty(postDTO.getPostTitle())) {
String slug = PostUtils.createSlug(postDTO.getPostTitle());
Post found = null;
try {
found = postService.getPost(slug);
} catch (PostNotFoundException e) {
// can be null for this check of a pre-existing post
}
if (sessionPost != null) {
if (found != null && !(found.getPostId().equals(sessionPost.getPostId()))) {
isDuplicate = true;
}
} else {
if (found != null)
isDuplicate = true;
}
}
return isDuplicate;
}
Aggregations