private void loadYouTubeThumbnails(Viewpoint viewpoint, ExternalAccountView accountView) {
    ExternalAccount account = accountView.getExternalAccount();

    if (account.getAccountType() != ExternalAccountType.YOUTUBE)
      throw new IllegalArgumentException("should be a YouTube account here");

    if (account.getSentiment() != Sentiment.LOVE)
      throw new IllegalArgumentException("YouTube account is unloved =(");

    if (account.getHandle() == null) return;

    try {
      youTubeUpdater.getCachedStatus(account);
    } catch (NotFoundException e) {
      logger.debug("No cached YouTube status for {}", account);
      return;
    }

    List<? extends YouTubeVideo> videos = youTubeVideosCache.getSync(account.getHandle());
    if (videos.isEmpty()) {
      logger.debug("Empty list of videos for {}", account);
      return;
    }

    accountView.setThumbnailsData(
        TypeUtils.castList(Thumbnail.class, videos),
        videos.size(),
        videos.get(0).getThumbnailWidth(),
        videos.get(0).getThumbnailHeight());
  }
Esempio n. 2
0
  public static int compare(ExternalAccount first, ExternalAccount second) {
    if (first.getOnlineAccountType().equals(second.getAccountType()))
      if (first.isMugshotEnabledWithDefault()) return -1;
      else if (second.isMugshotEnabledWithDefault()) return 1;
      else return 0;

    // We want "my website" first, "blog" second, then everything alphabetized by the human-readable
    // name.

    if (first.getAccountType() == ExternalAccountType.WEBSITE) return -1;
    if (second.getAccountType() == ExternalAccountType.WEBSITE) return 1;
    if (first.getAccountType() == ExternalAccountType.BLOG) return -1;
    if (second.getAccountType() == ExternalAccountType.BLOG) return 1;

    return String.CASE_INSENSITIVE_ORDER.compare(
        first.getOnlineAccountType().getFullName(), second.getOnlineAccountType().getFullName());
  }
  public ExternalAccountView getExternalAccountView(
      Viewpoint viewpoint, ExternalAccount externalAccount) {
    ExternalAccountView view;
    if (externalAccount.getAccountType() == ExternalAccountType.FACEBOOK) {
      view =
          new ExternalAccountView(externalAccount, facebookSystem.getProfileLink(externalAccount));
    } else {
      view = new ExternalAccountView(externalAccount);
    }

    loadThumbnails(viewpoint, view);

    return view;
  }
  private void loadThumbnails(Viewpoint viewpoint, ExternalAccountView externalAccountView) {
    ExternalAccount externalAccount = externalAccountView.getExternalAccount();
    ExternalAccountType type = externalAccount.getAccountType();
    // you only have thumbnails for accounts you like
    if (externalAccount.getSentiment() != Sentiment.LOVE) return;

    switch (type) {
      case FLICKR:
        loadFlickrThumbnails(viewpoint, externalAccountView);
        break;
      case YOUTUBE:
        loadYouTubeThumbnails(viewpoint, externalAccountView);
        break;
      default:
        // most accounts lack thumbnails
        break;
    }
  }
  public Set<ExternalAccountView> getExternalAccountViews(Viewpoint viewpoint, User user) {
    // Right now we ignore the viewpoint, so this method is pretty pointless.
    // but if people use it, future code will work properly.

    // be sure the account is attached... the external accounts are lazy-loaded
    if (!em.contains(user.getAccount()))
      throw new RuntimeException("detached account in getExternalAccounts()");

    Set<ExternalAccount> accounts = user.getAccount().getExternalAccounts();
    // logger.debug("{} external accounts for user {}", accounts.size(), user);

    Set<ExternalAccountView> accountViews = new HashSet<ExternalAccountView>();
    for (ExternalAccount account : accounts) {
      if (account.getAccountType() == ExternalAccountType.FACEBOOK) {
        accountViews.add(new ExternalAccountView(account, facebookSystem.getProfileLink(account)));
      } else {
        accountViews.add(new ExternalAccountView(account));
      }
    }

    return accountViews;
  }
  private void loadFlickrThumbnails(Viewpoint viewpoint, ExternalAccountView accountView) {
    ExternalAccount account = accountView.getExternalAccount();

    if (account.getAccountType() != ExternalAccountType.FLICKR)
      throw new IllegalArgumentException("should be a flickr account here");

    if (account.getSentiment() != Sentiment.LOVE)
      throw new IllegalArgumentException("Flickr account is unloved");

    if (account.getHandle() == null) return;

    FlickrPhotosView photos = flickrUserPhotosCache.getSync(account.getHandle());
    if (photos == null) {
      logger.debug("No public photos for {}", account);
      return;
    }

    accountView.setThumbnailsData(
        TypeUtils.castList(Thumbnail.class, photos.getPhotos()),
        photos.getTotal(),
        FlickrPhotoSize.SMALL_SQUARE.getPixels(),
        FlickrPhotoSize.SMALL_SQUARE.getPixels());
  }