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();
}
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;
}
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;
}
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);
}
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;
}
Aggregations