use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class SolrPostTests method addPostWithAddToIndexService.
@Test
public void addPostWithAddToIndexService() throws Exception {
// using postId 10 which is "Solr Rama"
Post post = postService.getPostById(10L);
postDocService.addToIndex(post);
PostDoc found = customPostDocRepository.findOne("10");
assertEquals(found.getPostName(), "solr-rama");
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class SolrUI method runDemos.
private void runDemos(DEMO demo) {
Query query = new SimpleQuery(new SimpleStringCriteria("doctype:post"));
List<Post> posts = postService.getAllPublishedPosts();
switch(demo) {
case MORE_LIKE_THIS:
PostDoc postDoc = postDocService.getPostDocByPostId(435L);
printPost(postDoc);
postDocList = postDocService.getMoreLikeThis(435L).subList(0, 2);
printPosts(postDocList);
break;
case POPULATE_DATABASE_SINGLE_ENTRIES:
solrOperations.delete(query);
solrOperations.commit();
System.out.println("Existing posts deleted...");
for (Post post : posts) {
System.out.println(String.format("Entering Post #%s : %s", post.getPostId(), post.getPostTitle()));
postDocService.addToIndex(post);
}
System.out.println("All posts added to Solr Server at " + solrSettings.getSolrServerUrl());
break;
case POPULATE_DATABASE_AS_LIST:
solrOperations.delete(query);
solrOperations.commit();
System.out.println("Existing posts deleted...");
postDocService.addAllToIndex(posts);
System.out.println("All posts added to Solr Server at " + solrSettings.getSolrServerUrl());
break;
case BY_LOCATION:
try {
productList = service.getProductsByLocation("35.10,-96.102");
} catch (GeoLocationException e) {
e.printStackTrace();
}
printProducts(productList);
break;
case HIGHLIGHT_SEARCH_CRITERIA:
highlightProductPage = service.findByHighlightedNameCriteria("canon powershot");
SolrUtils.processHighlights(highlightProductPage);
printProducts(highlightProductPage);
break;
case HIGHLIGHT_SEARCH:
String queryString = "Can on yep";
Boolean matches = queryString.matches("[a-zA-Z_0-9 ]*");
System.out.println("MATCHES: " + matches);
// printProducts(highlightProductPage);
break;
case SIMPLE_QUERY:
// productList = service.getProductsWithUserQuery("name:memory AND name:corsair) AND
// popularity:[6 TO *]");
// productList = service.getProductsWithUserQuery("name:Western+Digital AND inStock:TRUE");
// productList = service.getProductsWithUserQuery("cat:memory");
// productList = service.getProductsWithUserQuery("features::printer");
productList = service.getProductsWithUserQuery("inStock:true");
printProducts(productList);
break;
case FACET_ON_NAME:
facetProductPage = service.autocompleteNameFragment("pr", new PageRequest(0, 1));
Page<FacetFieldEntry> fnPage = facetProductPage.getFacetResultPage(Product.NAME_FIELD);
for (FacetFieldEntry entry : fnPage) {
System.out.println(String.format("%s:%s \t %s", entry.getField().getName(), entry.getValue(), entry.getValueCount()));
}
break;
case FACET_ON_AVAILABLE:
facetProductPage = service.getFacetedProductsAvailable();
Page<FacetFieldEntry> avPage = facetProductPage.getFacetResultPage(Product.AVAILABLE_FIELD);
for (FacetFieldEntry entry : avPage) {
System.out.println(String.format("%s:%s \t %s", entry.getField().getName(), entry.getValue(), entry.getValueCount()));
}
break;
case FACET_ON_CATEGORY:
facetProductPage = service.getFacetedProductsCategory();
Page<FacetFieldEntry> catPage = facetProductPage.getFacetResultPage(Product.CATEGORY_FIELD);
for (FacetFieldEntry entry : catPage) {
System.out.println(String.format("%s:%s \t %s", entry.getField().getName(), entry.getValue(), entry.getValueCount()));
}
break;
case METHOD_NAME_QUERY:
productList = service.getProductsByStartOfName("power cord");
printProducts(productList);
break;
case ANNOTATED_QUERY:
productList = service.getProductsByNameOrCategoryAnnotatedQuery("canon");
printProducts(productList);
break;
case NAMED_QUERY:
productIterable = service.getProductsByNameOrCategory("canon");
printProducts(productIterable);
break;
case TEST_RECORDS:
productListPage = service.getTestRecords();
printProducts(productListPage);
break;
case AVAILABLE_PRODUCTS:
productList = service.getAvailableProducts();
printProducts(productList);
break;
case ALL_PRODUCTS:
// productList = service.getProductsByFilter();
// printProducts(productList);
productList = service.getProducts();
printProducts(productList);
break;
case ALL_RECORDS:
Iterable<Product> allRecords = service.getAllRecords();
List<Product> productList = new ArrayList<>();
for (Product product : allRecords) {
if (product.getDoctype().equals(SolrDocType.PRODUCT))
productList.add(product);
}
printProducts(productList);
break;
case UPDATE_RECORD:
Product urProduct = service.getProduct(SOLR_RECORD_ID);
System.out.println(String.format("Original Product Name: %s", urProduct.getName()));
urProduct.setName("Solr, The Enterprisey Http Search Server");
service.updateProductName(urProduct);
Product urProductUpdated = service.getProduct(SOLR_RECORD_ID);
System.out.println(String.format("New Product Name: %s", urProductUpdated.getName()));
urProductUpdated.setName("Solr, The Enterprise Http Search Server");
service.updateProductName(urProductUpdated);
break;
case CRITERIA_SEARCH:
this.productList = service.searchWithCriteria("Canon Camera memory");
printProducts(this.productList);
break;
default:
break;
}
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class PostsRestControllerTests method moreLikeThis_DisplaySetTrue.
@Test
public void moreLikeThis_DisplaySetTrue() throws Exception {
// MoreLikeThis Posts Enabled, returns an HTML Response
applicationSettings.setMoreLikeThisDisplay(true);
List<Post> posts = postService.getAllPosts();
postDocService.reindexPosts(posts);
mockMvc.perform(get("/post/" + MLT_POSTNAME)).andExpect(model().attributeExists(MORELIKETHIS_ATTRIBUTE));
MvcResult mvcResult = mockMvc.perform(get("/json/posts/post/mlt/" + MLT_POSTID)).andExpect(status().isOk()).andDo(MockMvcResultHandlers.print()).andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)).andReturn();
assertThat(mvcResult.getResponse().getContentAsString(), containsString("<div class=\"mlt-item\">"));
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsController method createPost.
@RequestMapping(value = "/add/post", method = POST)
public String createPost(@Valid PostDTO postDTO, BindingResult result, CurrentUser currentUser, RedirectAttributes attributes, Model model, HttpServletRequest request) throws DuplicatePostNameException, PostNotFoundException {
String saveAction = request.getParameter("post");
model.addAttribute("postheader", webUI.getMessage(ADD_POST_HEADER));
model.addAttribute("hasPost", true);
model.addAttribute("canPreview", false);
Post sessionPost = null;
Object obj = WebUtils.getSessionAttribute(request, SESSION_ATTRIBUTE_NEWPOST);
if (obj != null) {
sessionPost = (Post) WebUtils.getSessionAttribute(request, SESSION_ATTRIBUTE_NEWPOST);
}
if (!isDuplicatePost(postDTO, sessionPost)) {
if (result.hasErrors()) {
model.addAttribute("postDTO", postDTO);
return ADMIN_POST_ADD_VIEW;
} else {
postDTO.setDisplayType(postDTO.getDisplayType());
postDTO.setPostName(PostUtils.createSlug(postDTO.getPostTitle()));
postDTO.setUserId(currentUser.getId());
postDTO.setPostContent(cleanContentTailHtml(postDTO.getPostContent()));
postDTO.setIsPublished(saveAction.equals(POST_PUBLISH));
postDTO.setTwitterCardType(postDTO.getTwitterCardType());
postDTO.setCategoryId(postDTO.getCategoryId());
request.setAttribute("postTitle", postDTO.getPostTitle());
Post saved;
if (sessionPost == null)
saved = postService.add(postDTO);
else {
postDTO.setPostId(sessionPost.getPostId());
saved = postService.update(postDTO);
}
postDTO.setPostId(saved.getPostId());
if (sessionPost == null)
saved.setPostMeta(jsoupService.createPostMeta(postDTO));
else
saved.setPostMeta(jsoupService.updatePostMeta(postDTO));
WebUtils.setSessionAttribute(request, SESSION_ATTRIBUTE_NEWPOST, saved);
if (saveAction.equals(POST_PUBLISH)) {
if (saved.getIsPublished()) {
if (applicationSettings.getSolrEnabled()) {
postDocService.addToIndex(saved);
}
fmService.createPostAtoZs();
}
webUI.addFeedbackMessage(attributes, FEEDBACK_POST_POST_ADDED);
return "redirect:/admin/posts";
} else {
model.addAttribute("fileuploading", fmService.getFileUploadingScript());
model.addAttribute("fileuploaded", fmService.getFileUploadedScript());
model.addAttribute("postDTO", getUpdatedPostDTO(saved));
model.addAttribute("hasImageUploads", true);
model.addAttribute("canPreview", true);
model.addAttribute("postName", saved.getPostName());
model.addAttribute("categories", postService.getAdminSelectionCategories());
return ADMIN_POST_ADD_VIEW;
}
}
} else {
model.addAttribute("hasImageUploads", true);
result.reject("global.error.post.name.exists", new Object[] { postDTO.getPostTitle() }, "post name exists");
return ADMIN_POST_ADD_VIEW;
}
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsController method updatePostMetaData.
@RequestMapping(value = "/postmeta", params = "update", method = GET)
public ModelAndView updatePostMetaData() {
ModelAndView mav = new ModelAndView();
List<Post> posts = postService.getAllPublishedPosts();
int postMetaCount = posts.size();
long lStartTime = new Date().getTime();
jsoupService.updateAllPostMeta(posts);
long lEndTime = new Date().getTime();
long duration = lEndTime - lStartTime;
String totalTime = String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration), TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)));
String updateMessage = webUI.getMessage(MESSAGE_ADMIN_SOLR_REINDEX_COMPLETE, postMetaCount, totalTime);
mav.addObject("updateMessage", updateMessage);
mav.addObject("hasPostMetaCount", true);
mav.setViewName(ADMIN_POSTMETA_UPDATE_VIEW);
return mav;
}
Aggregations