use of com.nixmash.blog.jpa.dto.PostDTO in project nixmash-blog by mintster.
the class AdminPostsController method addPostLink.
// endregion
// region Add Post GET
@RequestMapping(value = "/add/{type}", method = GET)
public String addPostLink(@PathVariable("type") String type, Model model, HttpServletRequest request) {
PostType postType = PostType.valueOf(type.toUpperCase());
model.addAttribute("postDTO", new PostDTO());
model.addAttribute("canPreview", false);
model.addAttribute("categories", postService.getAdminSelectionCategories());
if (postType == PostType.POST) {
WebUtils.setSessionAttribute(request, SESSION_ATTRIBUTE_NEWPOST, null);
model.addAttribute("hasPost", true);
model.addAttribute("postheader", webUI.getMessage(ADD_POST_HEADER));
return ADMIN_POST_ADD_VIEW;
} else {
model.addAttribute("postLink", new PostLink());
model.addAttribute("postheader", webUI.getMessage(ADD_LINK_HEADER));
return ADMIN_LINK_ADD_VIEW;
}
}
use of com.nixmash.blog.jpa.dto.PostDTO in project nixmash-blog by mintster.
the class AdminPostsController method updatePost.
// endregion
// region Update Posts GET POST
@RequestMapping(value = "/update/{postId}", method = GET)
public String updatePost(@PathVariable("postId") Long postId, Model model, HttpServletRequest request) throws PostNotFoundException {
Post post = postService.getPostById(postId);
String postType = StringUtils.capitalize(post.getPostType().name().toLowerCase());
String pageTitle = webUI.getMessage(MESSAGE_ADMIN_UPDATE_POSTLINK_TITLE, postType);
String pageHeading = webUI.getMessage(MESSAGE_ADMIN_UPDATE_POSTLINK_HEADING, postType);
PostDTO postDTO = getUpdatedPostDTO(post);
if (post.getPostType() == PostType.LINK) {
postDTO.setHasImages(post.getPostImage() != null);
postDTO.setPostImage(post.getPostImage());
if (postDTO.getHasImages()) {
model.addAttribute("hasLinkImage", true);
}
}
model.addAttribute("postName", post.getPostName());
model.addAttribute("postDTO", postDTO);
model.addAttribute("pageTitle", pageTitle);
model.addAttribute("pageHeading", pageHeading);
model.addAttribute("categories", postService.getAdminSelectionCategories());
model.addAllAttributes(getPostLinkAttributes(request, post.getPostType()));
return ADMIN_POSTLINK_UPDATE_VIEW;
}
use of com.nixmash.blog.jpa.dto.PostDTO 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);
}
use of com.nixmash.blog.jpa.dto.PostDTO in project nixmash-blog by mintster.
the class DemoJobItemProcessor method process.
@Override
public PostDTO process(final Post post) throws Exception {
final String postTitle = post.getPostTitle().toUpperCase();
PostDTO transformedPost = new PostDTO();
transformedPost.setPostTitle(postTitle);
return transformedPost;
}
use of com.nixmash.blog.jpa.dto.PostDTO in project nixmash-blog by mintster.
the class PostCachingTests method updatedPostIsRetrievedFromCache.
@Test
public void updatedPostIsRetrievedFromCache() throws Exception {
// Confirm our pagedPosts Cache is populated
postService.getPublishedPosts(0, 10);
assertThat(pagedPostsCache.get("0-10")).isNotNull();
// Update Post Title and call Post Update Service
String newTitle = "Something Wonderful";
Post post = postService.getPostById(1L);
String originalPostName = post.getPostName();
PostDTO postDTO = PostUtils.postToPostDTO(post);
postDTO.setPostTitle(newTitle);
postService.update(postDTO);
// Updated Post with New Title in Post Caches by Name and PostId
// AFTER it is evicted - Updated v0.4.5
assertNull(postCache.get(post.getPostName()));
postService.getPost(originalPostName);
Post postByName = (Post) postCache.get(post.getPostName()).get();
assertThat(postByName.getPostTitle()).isEqualTo(newTitle);
assertNull(postCache.get(post.getPostId()));
postService.getPostById(1L);
Post postById = (Post) postCache.get(post.getPostId()).get();
assertThat(postById.getPostTitle()).isEqualTo(newTitle);
// Paged Posts cache evicted on Post Update, rebuilt on next call
assertThat(pagedPostsCache.get("0-10")).isNull();
postService.getPublishedPosts(0, 10);
assertThat(pagedPostsCache.get("0-10")).isNotNull();
}
Aggregations