use of com.nixmash.blog.jpa.exceptions.PostNotFoundException in project nixmash-blog by mintster.
the class AdminPostsController method isDuplicatePost.
private Boolean isDuplicatePost(PostDTO postDTO, Post sessionPost) {
Boolean isDuplicate = false;
if (StringUtils.isNotEmpty(postDTO.getPostTitle())) {
String slug = PostUtils.createSlug(postDTO.getPostTitle());
Post found = null;
try {
found = postService.getPost(slug);
} catch (PostNotFoundException e) {
// can be null for this check of a pre-existing post
}
if (sessionPost != null) {
if (found != null && !(found.getPostId().equals(sessionPost.getPostId()))) {
isDuplicate = true;
}
} else {
if (found != null)
isDuplicate = true;
}
}
return isDuplicate;
}
use of com.nixmash.blog.jpa.exceptions.PostNotFoundException in project nixmash-blog by mintster.
the class PermaPostsControllerTests method notFoundPostName_ThrowsPostNotFoundException.
@Test(expected = PostNotFoundException.class)
public void notFoundPostName_ThrowsPostNotFoundException() throws Exception {
String badName = "bad-name";
when(postService.getPost(badName)).thenThrow(new PostNotFoundException());
mockMvc.perform(get("/post/" + badName)).andExpect(status().isOk()).andExpect(view().name("errors/custom"));
}
use of com.nixmash.blog.jpa.exceptions.PostNotFoundException 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;
}
use of com.nixmash.blog.jpa.exceptions.PostNotFoundException in project nixmash-blog by mintster.
the class AdminPostsControllerTests method badPostIdOnPostUpdate_ThrowsPostNotFoundException.
@Test(expected = PostNotFoundException.class)
public void badPostIdOnPostUpdate_ThrowsPostNotFoundException() throws Exception {
when(postService.getPostById(-2L)).thenThrow(new PostNotFoundException());
mvc.perform(get("/admin/posts/update/-2")).andExpect(status().isOk()).andExpect(view().name("errors/custom"));
}
Aggregations