Search in sources :

Example 41 with Post

use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.

the class GeneralController method home.

// endregion
// region Pages
@RequestMapping(value = "/", method = GET)
public String home(Model model) {
    String springVersion = webUI.parameterizedMessage("home.spring.version", SpringBootVersion.getVersion());
    model.addAttribute("springVersion", springVersion);
    GitHubStats gitHubStats = webUI.getCurrentGitHubStats();
    if (gitHubStats != null) {
        model.addAttribute("showGitHubStats", true);
        model.addAttribute("gitHubStats", gitHubStats);
    }
    if (webUI.isNixMash()) {
        SiteImage siteImage = siteService.getHomeBanner();
        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 : GitHubStats(com.nixmash.blog.jpa.model.GitHubStats) Post(com.nixmash.blog.jpa.model.Post) SiteImage(com.nixmash.blog.jpa.model.SiteImage)

Example 42 with Post

use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.

the class PermaPostsController method post.

// endregion
@GetMapping(value = "/post/{postName}")
public String post(@PathVariable("postName") String postName, @RequestParam(value = "preview", required = false, defaultValue = "false") Boolean inPreviewMode, Model model, CurrentUser currentUser) throws PostNotFoundException {
    Post post = postService.getPost(postName);
    Date postCreated = Date.from(post.getPostDate().toInstant());
    post.setIsOwner(PostUtils.isPostOwner(currentUser, post.getUserId()));
    post.setPostContent(PostUtils.formatPostContent(post));
    if (!inPreviewMode) {
        if (applicationSettings.getMoreLikeThisDisplay()) {
            // Solr must be active and number of postDocs retrieved must not be null
            if (postDocService.getMoreLikeThis(post.getPostId()) != null) {
                model.addAttribute("moreLikeThisDisplay", true);
                model.addAttribute("postId", post.getPostId());
                model.addAttribute("moreLikeThisHeading", webUI.getMessage(MORELIKETHIS_HEADING));
            }
        }
        PostMeta postMeta = postService.buildTwitterMetaTagsForDisplay(post);
        if (postMeta != null) {
            model.addAttribute("twitterMetatags", fmService.getTwitterTemplate(postMeta));
        }
    }
    model.addAttribute("post", post);
    model.addAttribute("postCreated", postCreated);
    model.addAttribute("shareSiteName", StringUtils.deleteWhitespace(applicationSettings.getSiteName()));
    model.addAttribute("shareUrl", String.format("%s/post/%s", applicationSettings.getBaseUrl(), post.getPostName()));
    return POSTS_PERMALINK_VIEW;
}
Also used : PostMeta(com.nixmash.blog.jpa.model.PostMeta) Post(com.nixmash.blog.jpa.model.Post) Date(java.util.Date) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 43 with Post

use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.

the class AdminPostsControllerTests method updatedPostUpdatesTwitterCardInfo.

@Test
public void updatedPostUpdatesTwitterCardInfo() throws Exception {
    Post post = postService.getPostById(1L);
    assert (post.getPostMeta().getTwitterCardType().equals(TwitterCardType.SUMMARY));
    RequestBuilder request = post("/admin/posts/update").param("postId", "1").param("displayType", String.valueOf(post.getDisplayType())).param("postContent", post.getPostContent()).param("postTitle", post.getPostTitle()).param("twitterCardType", TwitterCardType.SUMMARY_LARGE_IMAGE.name()).param("tags", "one, two").param("categoryId", "3").with(csrf());
    mvc.perform(request);
    post = postService.getPostById(1L);
    assert (post.getPostMeta().getTwitterCardType().equals(TwitterCardType.SUMMARY_LARGE_IMAGE));
}
Also used : RequestBuilder(org.springframework.test.web.servlet.RequestBuilder) Post(com.nixmash.blog.jpa.model.Post) Test(org.junit.Test)

Example 44 with Post

use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.

the class AdminPostsControllerTests method updatedPostTitleInAzIncludeFile.

@Test
public void updatedPostTitleInAzIncludeFile() throws Exception {
    String newTitle = "New Title for updatedPostTitleInAzIncludeFile Test";
    Post post = postService.getPostById(1L);
    RequestBuilder request = post("/admin/posts/update").param("postId", "1").param("displayType", String.valueOf(post.getDisplayType())).param("postContent", post.getPostContent()).param("postTitle", newTitle).param("twitterCardType", TWITTER_SUMMARY).param("tags", "one, two").with(csrf());
    mvc.perform(request);
    File azFile = new File(azTestFileName);
    String contents = FileUtils.readFileToString(azFile);
    assertTrue(contents.contains(newTitle));
}
Also used : RequestBuilder(org.springframework.test.web.servlet.RequestBuilder) Post(com.nixmash.blog.jpa.model.Post) File(java.io.File) Test(org.junit.Test)

Example 45 with Post

use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.

the class AdminPostsControllerTests method removingTagFromPostDecreasesItsTagCount.

@Test
public void removingTagFromPostDecreasesItsTagCount() throws Exception {
    Post post = postService.getPostById(1L);
    int postTagStartCount = post.getTags().size();
    // tag size of Post 1L is 3. Could be any value.
    // We are assigning a new tag, so the postTagEndCount
    // should be 2 less, or rather, always 1
    mvc.perform(post("/admin/posts/update").param("postId", "1").param("displayType", String.valueOf(post.getDisplayType())).param("postContent", post.getPostContent()).param("postTitle", post.getPostTitle()).param("twitterCardType", TWITTER_SUMMARY).param("tags", "removingTag1").param("categoryId", "1").with(csrf()));
    int postTagEndCount = post.getTags().size();
    assertEquals(postTagEndCount, 1);
    Post verifyPost = postService.getPostById(1L);
    assertEquals(verifyPost.getTags().size(), postTagEndCount);
}
Also used : Post(com.nixmash.blog.jpa.model.Post) 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