private static void fetchLikesAndUpdateUsers(Post post, Set<User> users, Page page) { PagedList<Reference> likes = facebook.likeOperations().getLikes(post.getId()); int totalLikes = likes.size(); for (Reference userLike : likes) { User user = users .stream() .filter(f -> f.getId().equals(userLike.getId())) .findFirst() .orElse(new User(userLike.getId(), userLike.getName(), page)); user.addLike(post, page.getId()); users.add(user); } while (likes.getNextPage() != null) { likes = facebook.likeOperations().getLikes(post.getId(), likes.getNextPage()); totalLikes += likes.size(); for (Reference userLike : likes) { User user = users .stream() .filter(f -> f.getId().equals(userLike.getId())) .findFirst() .orElse(new User(userLike.getId(), userLike.getName(), page)); user.addLike(post, page.getId()); users.add(user); } } post.getExtraData().putIfAbsent("likesCount", totalLikes); }
public UserAccount fillLocationFromFacebook(UserAccount userAccount) { Reference fbhome = facebook.userOperations().getUserProfile().getHometown(); String loca = ""; // FIXME move to "submit" if (fbhome != null) { List<YahooPlaceResult> places = yahooPlaceFinderService.searchPlaceResult(fbhome.getName()); Location location = new Location(); if (places.size() > 0) { YahooPlaceResult place = places.get(0); location.setCity(place.getCity()); location.setLatitude(place.getLatitude().floatValue()); location.setLongitude(place.getLongitude().floatValue()); location.setStateInitial(place.getStateCode()); Zip zip = null; try { zip = Zip.findZipsByZipCode(place.getUzip().toString()).getSingleResult(); } catch (NoResultException e) { zip = new Zip(); zip.setZipCode(place.getUzip().toString()); zip.setLatitude(place.getLatitude().floatValue()); zip.setLongitude(place.getLongitude().floatValue()); zip.persist(); } location.setZip(zip); // POINT( LON LAT ) // userAccount.setWkt("POINT( " + place.getLongitude() + " " + place.getLatitude() + " // )"); userAccount.setWktLocation(place.getLongitude(), place.getLatitude()); } userAccount.setLocation(location); } return userAccountService.updateUserAccount(userAccount); }