Search in sources :

Example 11 with Post

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

Example 12 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 13 with Post

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

Example 14 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 15 with Post

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://"));
}
Also used : Post(com.nixmash.blog.jpa.model.Post) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

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