@Test public void oneToOneToMany_projection() { Map<String, User> results = USERS_W_LATEST_POST_AND_COMMENTS.transform( groupBy(userName).as(Projections.constructor(User.class, userName, Projections.constructor(Post.class, postId, postName, set(qComment))))); assertEquals(2, results.size()); User user = results.get("Jane"); Post post = user.getLatestPost(); assertEquals(toInt(2), post.getId()); assertEquals("post 2", post.getName()); assertEquals(toSet(comment(4), comment(5)), post.getComments()); }
@Override protected Post transform(Group group) { return new Post( group.getOne(postId), group.getOne(postName), group.getSet(qComment)); } });
@RequestMapping(value = "/facebook/get", method = RequestMethod.GET) public ModelAndView getFacebookStatus() { logger.debug("ENTERING getFacebookStatus"); facebook = new FacebookTemplate("CAACEdEose0cBAJxfcf9xRQsL5un1WeEyIe2dy2xjI0EmuwzNbCWCPrTGwbsukRfQNb5ojQepPsMEjZAEXVwWfbYNA2fQO72kS3SPimt3ZCud4ykUZCoFkxZC6ks64dneZCNXLLJGRcqLeQ6DBPGwMrWtaSfi3W0zJLwDG1eu5FUsWJzgVZBwV4RmQvhhR4Yh0JfmyJSEU5am4L7rYJTUK0GtcYflhYlDMZD"); ModelAndView modelAndView = new ModelAndView("index"); // PagedList<Post> posts = facebook.feedOperations().getFeed(); // for(Post post : posts) { System.out.println(post.getMessage()); } Post post = facebook.feedOperations().getFeed().get(0); FacebookModel facebookModel = new FacebookModel(); facebookModel.setPostId(post.getId()); // facebookModel.setToProfile(post.getTo().get(0).getName()); facebookModel.setToProfile("Hi"); facebookModel.setFromProfile(post.getFrom().getName()); facebookModel.setCreatedTime(post.getCreatedTime()); facebookModel.setUpdatedTime(post.getUpdatedTime()); facebookModel.setMessage(post.getMessage()); facebookModel.setPictureUrl(post.getPicture()); modelAndView.addObject("facebookModel", facebookModel); logger.debug("EXITING getFacebookStatus"); return modelAndView; }
String message = post.getMessage(); PagableList<Comment> comments = post.getComments(); String date = post.getCreatedTime().toString(); String name = post.getFrom().getName(); String id = post.getId();
Collections.sort(posts, new Comparator<Post>() { @Override public int compare(Post lhs, Post rhs) { return ComparatorChain.start() .compare(lhs.getName(), rhs.getName(), String.CASE_INSENSITIVE_ORDER) .compare(lhs.getName(), rhs.getName()) .compare(lhs.getDate(), rhs.getDate()) .compare(lhs.getId(), rhs.getId()) .result(); } });
ResponseList<Post> results = facebook.getPosts(searchPost); String userId = ""; for (Post post : results) { obj.put("Post Id", post.getId()); obj.put("Post message", post.getMessage()); obj.put("No of likes on Post", post.getLikes().size()); obj.put("Post owner name:", post.getFrom().getName()); objArray = new JSONArray();
AsyncTask task = new AsyncTask<URL, Boolean, Boolean>() { @Override protected Boolean doInBackground(URL... params) { for (final DataSnapshot postSnapShot : dataSnapshot.getChildren()) { Post post = postSnapShot.getValue(Post.class); List<Post> publicPosts = application.getPublicAdapter().getPosts(); if (post.getPrivacy() == PrivacyEnum.Public && application.getPublicAdapter().containsId(publicPosts, post.getId()) == null) { application.getPublicAdapter().getPosts().add(0, post); } } return true; } @Override protected void onPostExecute(Boolean result) { if(result){ System.out.println("Finished executing public"); TabsUtil.populateNewsFeedList(fragmentView, application.getPublicAdapter(), TabEnum.Public, context); if (progressOverlay.getVisibility() == View.VISIBLE) { System.out.println("getPublicPosts: GONE"); AndroidUtils.animateView(progressOverlay, View.GONE, 0, 200); fragmentView.findViewById(R.id.rv_public_feed).setVisibility(View.VISIBLE); } } } };
//post_id and commentData received from view Post post=Post.findByPostId(post_id); //find post of that comment where findByPostId() is a function in model Comment comment=new Comment(commentData,null,post); //Create a new Comment Object Comment cm=Comment.save(comment); //where save() saves the Comment object in data base and return the saved object List <Comments> allCommentsOnPost=post.getComments(); //get all comments on that post allComments.add(cm); //add new comment to list post.setComments(allCommentsOnPost); //set the new list in Post object post.update(post_id); //update post entity
System.out.println(post.getMessage() +"===="+ + post.getSharesCount() + "====" + "====" + post.getId());
FaceBook faceBook = new FaceBookTemplate(accessToken); FeedOperations feeds=faceBook.feedOperations(); List<Post> posts=feeds.getPosts(); List<Comment> comments=new ArrayList<>(); for(Post post:posts){ List<Comment> commentsList = post.getComments(); for(Comment comment:commentsList){ comments.add(comment); } }
Collections.sort(posts, new Comparator<Post>() { @Override public int compare(Post lhs, Post rhs) { int nameComp = lhs.getName().compareToIgnoreCase(rhs.getName()); if (nameComp == 0) { Integer lhsSize = lhs.getSize(); Integer rhsSize = rhs.getSize(); return lhsSize.compareTo(rhsSize); } else { return nameComp; } } });
Post post = (Post) session.load(Post.class, new Long(123)); // at this point, post refers to a proxy object created by Hibernate // in the background - no post or user data has been loaded from DB post.getId(); // post still refers to the proxy object User user = post.getUser(); // post is now loaded, but user not - it refers to a proxy object String name = user.getName(); // Now the user data is loaded from DB
convertView = mActivity.getLayoutInflater().inflate(R.layout.listlook, parent, false); ((TextView)convertView.findViewById(R.id.txtl1)).setText(post.getName()); ((TextView)convertView.findViewById(R.id.txtl2)).setText(post.getComment()); return convertView;
Post post = postSnapShot.getValue(Post.class); List<Post> publicPosts = application.getPublicAdapter().getPosts(); if (post.getPrivacy().equals("Public") && application.getPublicAdapter().containsId(publicPosts, post.getId()) == null) { application.getPublicAdapter().getPosts().add(0, post);
public List<Comment> getComments(Post post) { List<Comment> fullComments = new ArrayList<>(); try { // get first few comments using getComments from post PagableList<Comment> comments = post.getComments(); Paging<Comment> paging; do { for (Comment comment: comments) fullComments.add(comment); // get next page // NOTE: somehow few comments will not be included. // however, this won't affect much on our research paging = comments.getPaging(); } while ((paging != null) && ((comments = fb_.fetchNext(paging)) != null)); } catch (FacebookException ex) { Logger.getLogger(Facebook.class.getName()) .log(Level.SEVERE, null, ex); } return fullComments; }
Collections.sort(posts, new Comparator<Post>() { @Override public int compare(Post lhs, Post rhs) { String left = lhs.getName().toLowerCase(); String right = rhs.getName().toLowerCase(); if (left.equals(right)) { return lhs.getName().compareTo(rhs.getName()); } else { return left.compareTo(right); } });
@Test public void transform_results() { List<Post> results = POST_W_COMMENTS.transform( groupBy(postId).list(Projections.constructor(Post.class, postId, postName, set(qComment)))); assertEquals(4, results.size()); Post post = results.get(1); assertNotNull(post); assertEquals(toInt(1), post.getId()); assertEquals("post 1", post.getName()); assertEquals(toSet(comment(1), comment(2), comment(3)), post.getComments()); }
@ApiMethod(name = "getPostComments") public List<CommentResults> getPostComments(@Named("postId") Long postId) { EntityManager mgr = getEntityManager(); List<CommentResults> results = new ArrayList<Comment>(); try { Post p = mgr.find(Post.class, postId); if (p == null) { throw new EntityNotFoundException("Post does not exist"); } else { for(Comment c:p.getComments()){ //copying the data CommentResults cr = new CommentResults(); cr.setMessage(c.getMessage); cr.setUserId(c.getUserId); results.add(cr); } } } finally { mgr.close(); } return results; }