Search in sources :

Example 6 with PostMeta

use of com.nixmash.blog.jpa.model.PostMeta 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 7 with PostMeta

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

the class AdminPostsControllerTests method newPostContainsTwitterCardInfo.

// endregion
// region Post MetaData
@Test
public void newPostContainsTwitterCardInfo() throws Exception {
    mvc.perform(addTwitterCardPostRequest("bigtwitter", TwitterCardType.SUMMARY_LARGE_IMAGE, PostDisplayType.POST));
    Post post = postService.getPost("my-title-bigtwitter");
    assertEquals(post.getPostMeta().getTwitterCardType(), TwitterCardType.SUMMARY_LARGE_IMAGE);
    PostMeta postMeta = postService.getPostMetaById(post.getPostId());
    assertNotNull(postMeta);
}
Also used : PostMeta(com.nixmash.blog.jpa.model.PostMeta) Post(com.nixmash.blog.jpa.model.Post) Test(org.junit.Test)

Example 8 with PostMeta

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

the class FmServiceTests method twitterSummaryLargeImageTemplate.

@Test
public void twitterSummaryLargeImageTemplate() throws PostNotFoundException {
    // H2 Post 10L SolrRama is SUMMARY_LARGE_IMAGE
    Post post = postService.getPostById(10L);
    PostMeta postMeta = postService.buildTwitterMetaTagsForDisplay(post);
    String result = fmService.getTwitterTemplate(postMeta);
    assertThat(result, containsString("summary_large_image"));
}
Also used : PostMeta(com.nixmash.blog.jpa.model.PostMeta) Post(com.nixmash.blog.jpa.model.Post) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 9 with PostMeta

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

the class JsoupServiceImpl method updatePostMeta.

@Override
@Transactional
public PostMeta updatePostMeta(PostDTO postDTO) {
    PostMeta postMeta = buildPostMetaToSave(postDTO);
    PostMeta updated = postMetaRepository.findByPostId(postDTO.getPostId());
    updated.update(postMeta.getTwitterImage(), postMeta.getTwitterCreator(), postMeta.getTwitterDescription(), postMeta.getTwitterCardType());
    return updated;
}
Also used : PostMeta(com.nixmash.blog.jpa.model.PostMeta) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with PostMeta

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

the class JsoupPostMetaTests method updatePostMeta.

@Test
public void updatePostMeta() throws PostNotFoundException {
    String NA = "na";
    PostMeta postMeta = postService.getPostMetaById(1L);
    assertEquals(postMeta.getTwitterDescription(), NA);
    PostDTO postDTO = PostUtils.postToPostDTO(postService.getPostById(1L));
    jsoupService.updatePostMeta(postDTO);
    postMeta = postService.getPostMetaById(1L);
    assertNotEquals(postMeta.getTwitterDescription(), NA);
}
Also used : PostMeta(com.nixmash.blog.jpa.model.PostMeta) PostDTO(com.nixmash.blog.jpa.dto.PostDTO) JsoupPostDTO(com.nixmash.blog.jsoup.dto.JsoupPostDTO) Test(org.junit.Test)

Aggregations

PostMeta (com.nixmash.blog.jpa.model.PostMeta)10 Post (com.nixmash.blog.jpa.model.Post)8 Test (org.junit.Test)7 Matchers.containsString (org.hamcrest.Matchers.containsString)2 PostDTO (com.nixmash.blog.jpa.dto.PostDTO)1 JsoupPostDTO (com.nixmash.blog.jsoup.dto.JsoupPostDTO)1 Date (java.util.Date)1 Transactional (org.springframework.transaction.annotation.Transactional)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1