@Test public void updateHendy() throws IOException { final String photoId = FacebookUtilsImpl.refreshPhotoFromFacebook(596326671L, "Hendy Irawan", personImageRepo); log.info("Photo ID is {}", photoId); Assert.assertNotNull(photoId); }
public static String refreshPhotoFromFacebook(final Long facebookId, final String personName, ImageRepository imageRepo) { final String photoUrl = "http: try (final CloseableHttpClient httpClient = HttpClients.createDefault()) { final HttpGet httpGet = new HttpGet(photoUrl); log.debug("Photo URL for Facebook user {} ({}) is {}", facebookId, personName, photoUrl); try (final CloseableHttpResponse response = httpClient.execute(httpGet)) { final File tmpFile = File.createTempFile("fb_", ".jpg"); try { FileUtils.copyInputStreamToFile(response.getEntity().getContent(), tmpFile); log.debug("Photo Status Line {}", response.getStatusLine()); final Predicate<String> predicate = new Predicate<String>() { @Override public boolean apply(String input) { return !imageRepo.exists(input); } }; final Image newImage = new Image(tmpFile, response.getEntity().getContentType().getValue(), personName + " Facebook " + facebookId, predicate); final String imageId = imageRepo.add(newImage).getId(); log.debug("tmp file path from Facebook user {} is {}", tmpFile); return imageId; } finally { tmpFile.delete(); } } } catch (final Exception e) { throw new RuntimeException("Cannot refresh Facebook user " + facebookId + " (" + personName +") from Facebook URI " + photoUrl, e); } }
FacebookUtilsImpl implements FacebookUtils { public static String refreshPhotoFromFacebook(final Long facebookId, final String personName, ImageRepository imageRepo) { final String photoUrl = "http: try (final CloseableHttpClient httpClient = HttpClients.createDefault()) { final HttpGet httpGet = new HttpGet(photoUrl); log.debug("Photo URL for Facebook user {} ({}) is {}", facebookId, personName, photoUrl); try (final CloseableHttpResponse response = httpClient.execute(httpGet)) { final File tmpFile = File.createTempFile("fb_", ".jpg"); try { FileUtils.copyInputStreamToFile(response.getEntity().getContent(), tmpFile); log.debug("Photo Status Line {}", response.getStatusLine()); final Predicate<String> predicate = new Predicate<String>() { @Override public boolean apply(String input) { return !imageRepo.exists(input); } }; final Image newImage = new Image(tmpFile, response.getEntity().getContentType().getValue(), personName + " Facebook " + facebookId, predicate); final String imageId = imageRepo.add(newImage).getId(); log.debug("tmp file path from Facebook user {} is {}", tmpFile); return imageId; } finally { tmpFile.delete(); } } } catch (final Exception e) { throw new RuntimeException("Cannot refresh Facebook user " + facebookId + " (" + personName +") from Facebook URI " + photoUrl, e); } } }
FacebookUtilsImpl implements FacebookUtils { public static String refreshPhotoFromFacebook(final Long facebookId, final String personName, ImageRepository imageRepo) { final String photoUrl = "http: try (final CloseableHttpClient httpClient = HttpClients.createDefault()) { final HttpGet httpGet = new HttpGet(photoUrl); log.debug("Photo URL for Facebook user {} ({}) is {}", facebookId, personName, photoUrl); try (final CloseableHttpResponse response = httpClient.execute(httpGet)) { final File tmpFile = File.createTempFile("fb_", ".jpg"); try { FileUtils.copyInputStreamToFile(response.getEntity().getContent(), tmpFile); log.debug("Photo Status Line {}", response.getStatusLine()); final Predicate<String> predicate = new Predicate<String>() { @Override public boolean apply(String input) { return !imageRepo.exists(input); } }; final Image newImage = new Image(tmpFile, response.getEntity().getContentType().getValue(), personName + " Facebook " + facebookId, predicate); final String imageId = imageRepo.add(newImage).getId(); log.debug("tmp file path from Facebook user {} is {}", tmpFile); return imageId; } finally { tmpFile.delete(); } } } catch (final Exception e) { throw new RuntimeException("Cannot refresh Facebook user " + facebookId + " (" + personName +") from Facebook URI " + photoUrl, e); } } @Inject  FacebookUtilsImpl(FriendListDownloader friendListDownloader,
			UserListParser userListParser); }
FacebookUtilsImpl implements FacebookUtils { public static String refreshPhotoFromFacebook(final Long facebookId, final String personName, ImageRepository imageRepo) { final String photoUrl = "http: try (final CloseableHttpClient httpClient = HttpClients.createDefault()) { final HttpGet httpGet = new HttpGet(photoUrl); log.debug("Photo URL for Facebook user {} ({}) is {}", facebookId, personName, photoUrl); try (final CloseableHttpResponse response = httpClient.execute(httpGet)) { final File tmpFile = File.createTempFile("fb_", ".jpg"); try { FileUtils.copyInputStreamToFile(response.getEntity().getContent(), tmpFile); log.debug("Photo Status Line {}", response.getStatusLine()); final Predicate<String> predicate = new Predicate<String>() { @Override public boolean apply(String input) { return !imageRepo.exists(input); } }; final Image newImage = new Image(tmpFile, response.getEntity().getContentType().getValue(), personName + " Facebook " + facebookId, predicate); final String imageId = imageRepo.add(newImage).getId(); log.debug("tmp file path from Facebook user {} is {}", tmpFile); return imageId; } finally { tmpFile.delete(); } } } catch (final Exception e) { throw new RuntimeException("Cannot refresh Facebook user " + facebookId + " (" + personName +") from Facebook URI " + photoUrl, e); } } @Inject  FacebookUtilsImpl(FriendListDownloader friendListDownloader,
			UserListParser userListParser); @Override List<HintPerson> findFriends(String accessToken); @Override List<HintPerson> findFriendsCached(String accessToken); static String refreshPhotoFromFacebook(final Long facebookId, final String personName,
			ImageRepository imageRepo); }
FacebookUtilsImpl implements FacebookUtils { public static String refreshPhotoFromFacebook(final Long facebookId, final String personName, ImageRepository imageRepo) { final String photoUrl = "http: try (final CloseableHttpClient httpClient = HttpClients.createDefault()) { final HttpGet httpGet = new HttpGet(photoUrl); log.debug("Photo URL for Facebook user {} ({}) is {}", facebookId, personName, photoUrl); try (final CloseableHttpResponse response = httpClient.execute(httpGet)) { final File tmpFile = File.createTempFile("fb_", ".jpg"); try { FileUtils.copyInputStreamToFile(response.getEntity().getContent(), tmpFile); log.debug("Photo Status Line {}", response.getStatusLine()); final Predicate<String> predicate = new Predicate<String>() { @Override public boolean apply(String input) { return !imageRepo.exists(input); } }; final Image newImage = new Image(tmpFile, response.getEntity().getContentType().getValue(), personName + " Facebook " + facebookId, predicate); final String imageId = imageRepo.add(newImage).getId(); log.debug("tmp file path from Facebook user {} is {}", tmpFile); return imageId; } finally { tmpFile.delete(); } } } catch (final Exception e) { throw new RuntimeException("Cannot refresh Facebook user " + facebookId + " (" + personName +") from Facebook URI " + photoUrl, e); } } @Inject  FacebookUtilsImpl(FriendListDownloader friendListDownloader,
			UserListParser userListParser); @Override List<HintPerson> findFriends(String accessToken); @Override List<HintPerson> findFriendsCached(String accessToken); static String refreshPhotoFromFacebook(final Long facebookId, final String personName,
			ImageRepository imageRepo);  }