Search in sources :

Example 1 with Post

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();
}
Also used : Post(com.nixmash.blog.jpa.model.Post)

Example 2 with Post

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;
    }
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PagePreviewDTO(com.nixmash.blog.jsoup.dto.PagePreviewDTO)

Example 3 with Post

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;
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostDTO(com.nixmash.blog.jpa.dto.PostDTO)

Example 4 with Post

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;
}
Also used : Post(com.nixmash.blog.jpa.model.Post) ModelAndView(org.springframework.web.servlet.ModelAndView) Date(java.util.Date)

Example 5 with Post

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;
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostNotFoundException(com.nixmash.blog.jpa.exceptions.PostNotFoundException)

Aggregations

Post (com.nixmash.blog.jpa.model.Post)68 Test (org.junit.Test)48 PostUtils.postDtoToPost (com.nixmash.blog.jpa.utils.PostUtils.postDtoToPost)15 PostDTO (com.nixmash.blog.jpa.dto.PostDTO)14 PostMeta (com.nixmash.blog.jpa.model.PostMeta)8 PostDoc (com.nixmash.blog.solr.model.PostDoc)8 Matchers.containsString (org.hamcrest.Matchers.containsString)5 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)5 ArrayList (java.util.ArrayList)4 Query (org.springframework.data.solr.core.query.Query)4 SimpleQuery (org.springframework.data.solr.core.query.SimpleQuery)4 SimpleStringCriteria (org.springframework.data.solr.core.query.SimpleStringCriteria)4 ZonedDateTime (java.time.ZonedDateTime)3 Date (java.util.Date)3 Before (org.junit.Before)3 TagDTO (com.nixmash.blog.jpa.dto.TagDTO)2 PostNotFoundException (com.nixmash.blog.jpa.exceptions.PostNotFoundException)2 SiteImage (com.nixmash.blog.jpa.model.SiteImage)2 JsonPostDTO (com.nixmash.blog.mvc.dto.JsonPostDTO)2 File (java.io.File)2