Search in sources :

Example 11 with PostDTO

use of com.nixmash.blog.jpa.dto.PostDTO in project nixmash-blog by mintster.

the class AdminPostsController method postDtoFromPagePreview.

private PostDTO postDtoFromPagePreview(PagePreviewDTO page, String postLink) {
    Boolean hasTwitter = page.getTwitterDTO() != null;
    String postTitle = hasTwitter ? page.getTwitterDTO().getTwitterTitle() : page.getTitle();
    String postDescription = hasTwitter ? page.getTwitterDTO().getTwitterDescription() : page.getDescription();
    PostDTO tmpDTO = getPagePreviewImage(page, postLink);
    if (postTitle == null)
        postTitle = page.getTitle();
    if (postDescription == null)
        postDescription = page.getDescription();
    String postDescriptionHtml = null;
    if (StringUtils.isNotEmpty(postDescription))
        postDescriptionHtml = String.format("<p>%s</p>", postDescription);
    return PostDTO.getBuilder(null, postTitle, null, postLink, postDescriptionHtml, PostType.LINK, null, 1L, TwitterCardType.SUMMARY).postImage(tmpDTO.getPostImage()).hasImages(tmpDTO.getHasImages()).build();
}
Also used : PostDTO(com.nixmash.blog.jpa.dto.PostDTO)

Example 12 with PostDTO

use of com.nixmash.blog.jpa.dto.PostDTO in project nixmash-blog by mintster.

the class AdminPostsController method getPagePreviewImage.

private PostDTO getPagePreviewImage(PagePreviewDTO page, String sourceLink, Integer imageIndex) {
    String postSource = PostUtils.createPostSource(sourceLink);
    PostDTO tmpDTO = new PostDTO();
    String imageUrl = null;
    Boolean hasImages = true;
    if (imageIndex == null) {
        if (page.twitterDTO != null) {
            imageUrl = page.getTwitterDTO().getTwitterImage();
            if (imageUrl != null) {
                if (!StringUtils.startsWithIgnoreCase(imageUrl, "http"))
                    imageUrl = null;
            }
        } else {
            if (page.getImages().size() > 1) {
                imageUrl = page.getImages().get(1).getSrc();
            } else
                hasImages = false;
        }
        if (StringUtils.isEmpty(imageUrl)) {
            hasImages = false;
            imageUrl = null;
        }
    } else {
        // determining the final postDTO from addLink form carousel index
        imageUrl = page.getImages().get(imageIndex).getSrc();
    }
    if (postSource != null) {
        switch(postSource.toLowerCase()) {
            case "stackoverflow.com":
                imageUrl = "/images/posts/stackoverflow.png";
                hasImages = false;
                break;
            case "spring.io":
            case "docs.spring.io":
                imageUrl = "/images/posts/spring.png";
                hasImages = false;
                break;
            case "github.com":
                imageUrl = "/images/posts/github.png";
                hasImages = false;
                break;
            default:
                break;
        }
    }
    tmpDTO.setPostImage(imageUrl);
    tmpDTO.setHasImages(hasImages);
    return tmpDTO;
}
Also used : PostDTO(com.nixmash.blog.jpa.dto.PostDTO)

Example 13 with PostDTO

use of com.nixmash.blog.jpa.dto.PostDTO in project nixmash-blog by mintster.

the class DemoJobConfiguration method demoJobWriter.

@Bean
public ItemWriter<PostDTO> demoJobWriter() {
    FlatFileItemWriter<PostDTO> writer = new FlatFileItemWriter<>();
    writer.setResource(new FileSystemResource("/home/daveburke/web/nixmashspring/posts.csv"));
    DelimitedLineAggregator<PostDTO> delLineAgg = new DelimitedLineAggregator<>();
    delLineAgg.setDelimiter(";");
    BeanWrapperFieldExtractor<PostDTO> fieldExtractor = new BeanWrapperFieldExtractor<>();
    fieldExtractor.setNames(new String[] { "postTitle" });
    delLineAgg.setFieldExtractor(fieldExtractor);
    writer.setLineAggregator(delLineAgg);
    return writer;
}
Also used : BeanWrapperFieldExtractor(org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor) FlatFileItemWriter(org.springframework.batch.item.file.FlatFileItemWriter) PostDTO(com.nixmash.blog.jpa.dto.PostDTO) FileSystemResource(org.springframework.core.io.FileSystemResource) DelimitedLineAggregator(org.springframework.batch.item.file.transform.DelimitedLineAggregator) Bean(org.springframework.context.annotation.Bean)

Example 14 with PostDTO

use of com.nixmash.blog.jpa.dto.PostDTO in project nixmash-blog by mintster.

the class JpaUI method addPostDemo.

private void addPostDemo() throws DuplicatePostNameException {
    String title = "Best way to create SEO friendly URI string";
    PostDTO postDTO = PostDTO.getBuilder(1L, title, PostUtils.createSlug(title), "http://nixmash.com/java/variations-on-json-key-value-pairs-in-spring-mvc/", "This is the post content", PostType.LINK, PostDisplayType.LINK_FEATURE, 1L, TwitterCardType.SUMMARY).build();
    postService.add(postDTO);
}
Also used : PostDTO(com.nixmash.blog.jpa.dto.PostDTO)

Example 15 with PostDTO

use of com.nixmash.blog.jpa.dto.PostDTO 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)

Aggregations

PostDTO (com.nixmash.blog.jpa.dto.PostDTO)24 Test (org.junit.Test)15 Post (com.nixmash.blog.jpa.model.Post)14 PostUtils.postDtoToPost (com.nixmash.blog.jpa.utils.PostUtils.postDtoToPost)9 TagDTO (com.nixmash.blog.jpa.dto.TagDTO)2 PostType (com.nixmash.blog.jpa.enums.PostType)1 Category (com.nixmash.blog.jpa.model.Category)1 PostMeta (com.nixmash.blog.jpa.model.PostMeta)1 JsoupPostDTO (com.nixmash.blog.jsoup.dto.JsoupPostDTO)1 PostLink (com.nixmash.blog.mvc.containers.PostLink)1 ArrayList (java.util.ArrayList)1 FlatFileItemWriter (org.springframework.batch.item.file.FlatFileItemWriter)1 BeanWrapperFieldExtractor (org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor)1 DelimitedLineAggregator (org.springframework.batch.item.file.transform.DelimitedLineAggregator)1 Bean (org.springframework.context.annotation.Bean)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1