Search in sources :

Example 31 with Post

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

the class SolrPostTests method setupSolr.

@Before
public void setupSolr() {
    Query query = new SimpleQuery(new SimpleStringCriteria("doctype:post"));
    solrOperations.delete(query);
    solrOperations.commit();
    List<Post> posts = postService.getAllPublishedPosts();
    postDocService.addAllToIndex(posts);
}
Also used : SimpleQuery(org.springframework.data.solr.core.query.SimpleQuery) Query(org.springframework.data.solr.core.query.Query) SimpleQuery(org.springframework.data.solr.core.query.SimpleQuery) Post(com.nixmash.blog.jpa.model.Post) SimpleStringCriteria(org.springframework.data.solr.core.query.SimpleStringCriteria) Before(org.junit.Before)

Example 32 with Post

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

the class SolrPostTests method updatedPost.

private Post updatedPost(String postTitle) throws PostNotFoundException {
    Post post = postService.getPostById(10L);
    PostDTO postDTO = PostUtils.postToPostDTO(post);
    postDTO.setPostTitle(postTitle);
    return postService.update(postDTO);
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostDTO(com.nixmash.blog.jpa.dto.PostDTO)

Example 33 with Post

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

the class AdminSolrPostsControllerTests method updatingPostUpdatesItsSolrPostDocument.

@Test
public void updatingPostUpdatesItsSolrPostDocument() throws Exception {
    List<PostDoc> postDocs = postDocService.getAllPostDocuments();
    int postDocCount = postDocs.size();
    Post post = postService.getPostById(1L);
    String originalTitle = post.getPostTitle();
    String newTitle = "updatingPostUpdatesItsSolrPostDocument";
    mvc.perform(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", "removingTag1").with(csrf()));
    // size of PostDocuments in Solr Index Unchanged
    assertEquals(postDocCount, postDocService.getAllPostDocuments().size());
    Post verifyPost = postService.getPostById(1L);
    assertEquals(verifyPost.getPostTitle(), newTitle);
    List<PostDoc> verifyPostDocs = postDocService.getPostsWithUserQuery(newTitle);
    assertEquals(verifyPostDocs.size(), 1);
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostDoc(com.nixmash.blog.solr.model.PostDoc) Test(org.junit.Test)

Example 34 with Post

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

the class AdminSolrPostsControllerTests method setup.

// endregion
// region Before / After
@Before
public void setup() throws ServletException {
    // ObjectMapper objectMapper = new ObjectMapper();
    // JacksonTester.initFields(this, objectMapper);
    mvc = webAppContextSetup(wac).apply(springSecurity()).build();
    Query query = new SimpleQuery(new SimpleStringCriteria("doctype:post"));
    solrOperations.delete(query);
    solrOperations.commit();
    List<Post> posts = postService.getAllPublishedPosts();
    postDocService.addAllToIndex(posts);
}
Also used : SimpleQuery(org.springframework.data.solr.core.query.SimpleQuery) Query(org.springframework.data.solr.core.query.Query) SimpleQuery(org.springframework.data.solr.core.query.SimpleQuery) Post(com.nixmash.blog.jpa.model.Post) SimpleStringCriteria(org.springframework.data.solr.core.query.SimpleStringCriteria) Before(org.junit.Before)

Example 35 with Post

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

the class PostDocServiceImpl method getMoreLikeThisPostsFromPostDocs.

@Transactional(readOnly = true)
@Override
public List<Post> getMoreLikeThisPostsFromPostDocs(List<PostDoc> postDocs) {
    List<Post> posts = new ArrayList<>();
    String result = StringUtils.EMPTY;
    for (int i = 0; i < applicationSettings.getMoreLikeThisNum(); i++) {
        try {
            PostDoc postDoc = postDocs.get(i);
            posts.add(postService.getPostById(Long.parseLong(postDoc.getPostId())));
        } catch (PostNotFoundException | IndexOutOfBoundsException e) {
            if (e.getClass().equals(PostNotFoundException.class))
                logger.info("MoreLikeThis PostDoc {} to Post with title \"{}\" NOT FOUND", postDocs.get(i).getPostId(), postDocs.get(i).getPostTitle());
            else {
                logger.info("EXCEPTION: AppSetting.MoreLikeThisNum > post count");
                return null;
            }
        }
    }
    return posts;
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostNotFoundException(com.nixmash.blog.jpa.exceptions.PostNotFoundException) ArrayList(java.util.ArrayList) PostDoc(com.nixmash.blog.solr.model.PostDoc) Transactional(org.springframework.transaction.annotation.Transactional)

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