Search in sources :

Example 51 with Post

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

the class PostsRestController method populatePostStream.

private String populatePostStream(List<Post> posts, CurrentUser currentUser, String format) {
    String result = StringUtils.EMPTY;
    for (Post post : posts) {
        try {
            if (post.getDisplayType().equals(PostDisplayType.MULTIPHOTO_POST)) {
                post.setPostImages(postService.getPostImages(post.getPostId()));
            }
            if (post.getDisplayType().equals(PostDisplayType.SINGLEPHOTO_POST)) {
                post.setSingleImage(postService.getPostImages(post.getPostId()).get(0));
            }
        } catch (Exception e) {
            logger.info(String.format("Image Retrieval Error for Post ID:%s Title: %s", String.valueOf(post.getPostId()), post.getPostTitle()));
        }
        post.setIsOwner(PostUtils.isPostOwner(currentUser, post.getUserId()));
        result += fmService.createPostHtml(post, format);
    }
    return result;
}
Also used : Post(com.nixmash.blog.jpa.model.Post) UncategorizedSolrException(org.springframework.data.solr.UncategorizedSolrException)

Example 52 with Post

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

the class PostTestUtils method createPostList.

public static List<Post> createPostList(int n) {
    List<Post> posts = new ArrayList<Post>(n);
    for (int i = 1; i < n + 1; i++) {
        PostDTO postDTO = createPostDTO(n);
        posts.add(PostUtils.postDtoToPost(postDTO));
    }
    return posts;
}
Also used : Post(com.nixmash.blog.jpa.model.Post) ArrayList(java.util.ArrayList) PostDTO(com.nixmash.blog.jpa.dto.PostDTO)

Example 53 with Post

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

the class PostRepoTests method savePostWithTags.

@Test
public void savePostWithTags() {
    Post post = Post.getBuilder(1L, "Post With Tags", "post-with-tags", null, "New post with tags!", PostType.POST, PostDisplayType.POST).build();
    Tag tag1 = new Tag("third tag");
    tag1 = tagRepository.save(tag1);
    Tag tag2 = new Tag("fourth tag");
    tag2 = tagRepository.save(tag2);
    Post saved = postRepository.save(post);
    saved.setTags(new HashSet<>());
    saved.getTags().add(tag1);
    saved.getTags().add(tag2);
    assertEquals(saved.getTags().size(), 2);
    postRepository.save(saved);
    List<Post> posts = postRepository.findAllWithDetail();
    Optional<Post> found = posts.stream().filter(p -> p.getPostId().equals(saved.getPostId())).findFirst();
    if (found.isPresent()) {
        assertEquals(found.get().getTags().size(), 2);
    }
}
Also used : PostTestUtils.getTestTags(com.nixmash.blog.jpa.utils.PostTestUtils.getTestTags) PostDisplayType(com.nixmash.blog.jpa.enums.PostDisplayType) Matchers.isA(org.hamcrest.Matchers.isA) DataConfigProfile(com.nixmash.blog.jpa.enums.DataConfigProfile) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) PostType(com.nixmash.blog.jpa.enums.PostType) Test(org.junit.Test) ActiveProfiles(org.springframework.test.context.ActiveProfiles) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) Post(com.nixmash.blog.jpa.model.Post) HashSet(java.util.HashSet) ApplicationConfig(com.nixmash.blog.jpa.config.ApplicationConfig) List(java.util.List) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Optional(java.util.Optional) Tag(com.nixmash.blog.jpa.model.Tag) Assert(org.junit.Assert) PostTestUtils.getTestCategory(com.nixmash.blog.jpa.utils.PostTestUtils.getTestCategory) Before(org.junit.Before) Post(com.nixmash.blog.jpa.model.Post) Tag(com.nixmash.blog.jpa.model.Tag) Test(org.junit.Test)

Example 54 with Post

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

the class PostRepoTests method nullPostLinkEnteredAndResultsInPostSourceAsNull.

@Test
public void nullPostLinkEnteredAndResultsInPostSourceAsNull() {
    Post post = Post.getBuilder(1L, "Nuther New Title", "nuther-new-title", null, "New post content!", PostType.POST, PostDisplayType.POST).build();
    Post saved = postRepository.save(post);
    assertNotNull(saved);
    assertNull(saved.getPostLink());
    assertEquals(saved.getPostSource(), null);
}
Also used : Post(com.nixmash.blog.jpa.model.Post) Test(org.junit.Test)

Example 55 with Post

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

the class PostRepoTests method retrievePostFromRepository.

@Test
public void retrievePostFromRepository() {
    Post post = postRepository.findByPostId(1L);
    assertNotNull(post);
}
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