public ExternalAccount lookupExternalAccount( Viewpoint viewpoint, User user, ExternalAccountType type) throws NotFoundException { if (!em.contains(user.getAccount())) throw new RuntimeException("detached account in lookupExternalAccount()"); // Right now, external accounts are public, unlike email/aim resources which are friends only... // so we don't need to use the viewpoint. But here in case we want to add it later. ExternalAccount external = user.getAccount().getExternalAccount(type); if (external == null) throw new NotFoundException("No external account of type " + type + " for user " + user); else return external; }
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; }