@Override
 public Project getProjectForInvitationToken(String token) throws NoSuchEntityException {
   try {
     return profileWebService.getProjectForInvitationToken(token);
   } catch (EntityNotFoundException e) {
     handle(e);
     throw new IllegalStateException();
   }
 }
 @Override
 public void removeSshPublicKey(Long publicKeyId) throws NoSuchEntityException {
   try {
     profileWebService.removeSshPublicKey(publicKeyId);
   } catch (EntityNotFoundException e) {
     handle(e);
     throw new IllegalStateException();
   }
 }
 @Override
 public SshPublicKey createSshPublicKey(SshPublicKeySpec publicKey)
     throws ValidationFailedException {
   try {
     return profileWebService.createSshPublicKey(publicKey);
   } catch (ValidationException e) {
     handle(e);
     throw new IllegalStateException();
   }
 }
  @Override
  public Boolean isWatchingProject(String projectIdentifier) throws NoSuchEntityException {
    setTenancyContext(projectIdentifier);

    try {
      return profileWebService.isWatchingProject(projectIdentifier);
    } catch (EntityNotFoundException e) {
      handle(e);
      throw new IllegalStateException();
    }
  }
  @Override
  public void unwatchProject(String projectIdentifier) throws NoSuchEntityException {
    setTenancyContext(projectIdentifier);

    try {
      profileWebService.unwatchProject(projectIdentifier);
    } catch (EntityNotFoundException e) {
      handle(e);
      throw new IllegalStateException();
    }
  }
 private List<com.tasktop.c2c.server.profile.domain.project.Agreement> getPendingAgreements()
     throws NoSuchEntityException {
   List<com.tasktop.c2c.server.profile.domain.project.Agreement> agreements;
   try {
     agreements = profileWebService.getPendingAgreements();
     return agreements;
   } catch (EntityNotFoundException e) {
     handle(e);
     throw new IllegalStateException();
   }
 }
  private Credentials getCurrentUser() {
    com.tasktop.c2c.server.profile.domain.project.Profile profile =
        profileWebService.getCurrentProfile();
    if (profile == null) {
      return null;
    }
    List<String> roles = new ArrayList<String>();

    if (SecurityContextHolder.getContext().getAuthentication() != null) {
      for (GrantedAuthority authority :
          SecurityContextHolder.getContext().getAuthentication().getAuthorities()) {
        roles.add(authority.getAuthority());
      }
    }

    return new Credentials(profile, roles);
  }
 @Override
 public UserInfo createProfileWithSignUpToken(
     com.tasktop.c2c.server.profile.domain.project.Profile profile, String token)
     throws NoSuchEntityException, ValidationFailedException {
   try {
     profileWebService.createProfileWithSignUpToken(profile, token);
     logon(profile.getUsername(), profile.getPassword(), false);
     return getCurrentUserInfo();
   } catch (EntityNotFoundException e) {
     handle(e);
     throw new IllegalStateException();
   } catch (ValidationException e) {
     handle(e);
     throw new IllegalStateException();
   } catch (AuthenticationFailedException e) {
     // should never happen
     throw new IllegalStateException(e);
   }
 }
  @Override
  public Credentials updateProfile(com.tasktop.c2c.server.profile.domain.project.Profile p)
      throws ValidationFailedException, NoSuchEntityException {
    try {
      profileWebService.updateProfile(p);
      String newPassword = p.getPassword();
      if (newPassword != null && newPassword.length() > 0) {
        return logon(p.getUsername(), newPassword, false);
      }
      return getCurrentUser();
    } catch (ValidationException e) {
      handle(e);
    } catch (EntityNotFoundException e) {
      handle(e);
    } catch (AuthenticationFailedException e) {
      // should never happen
      throw new IllegalStateException(e);
    }

    // should never happen
    throw new IllegalStateException();
  }
 @Override
 public QueryResult<Project> findProjects(ProjectsQuery query) {
   return profileWebService.findProjects(query);
 }