@Override
 public List<Profile> getProfiles(String projectIdentifier, String query, int limit)
     throws NoSuchEntityException {
   com.tasktop.c2c.server.profile.domain.internal.Project project;
   try {
     project = profileService.getProjectByIdentifier(projectIdentifier);
   } catch (EntityNotFoundException e) {
     handle(e);
     throw new IllegalStateException();
   }
   List<Profile> profiles = new ArrayList<Profile>();
   for (ProjectProfile profile : project.getProjectProfiles()) {
     Profile copy = webServiceDomain.copy(profile.getProfile());
     if (matches(query, copy)) {
       profiles.add(copy);
     }
   }
   Collections.sort(profiles);
   if (limit > 0) {
     while (profiles.size() > limit) {
       profiles.remove(profiles.size() - 1);
     }
   }
   // don't leak email addresses
   for (Profile profile : profiles) {
     profile.setEmail(null);
   }
   return profiles;
 }
  @Override
  public boolean removeTeamMember(String projectIdentifier, ProjectTeamMember member)
      throws NoSuchEntityException, ValidationFailedException {
    setTenancyContext(projectIdentifier);

    com.tasktop.c2c.server.profile.domain.internal.Project project;
    try {
      project = profileService.getProjectByIdentifier(projectIdentifier);
    } catch (EntityNotFoundException e) {
      handle(e);
      throw new IllegalStateException();
    }
    try {
      profileService.removeProjectProfile(project.getId(), member.getProfile().getId());
    } catch (EntityNotFoundException e) {
      handle(e);
      throw new IllegalStateException();
    } catch (ValidationException e) {
      handle(e);
      throw new IllegalStateException();
    }
    return true;
  }
  @Override
  public Boolean updateTeamMemberRoles(String projectIdentifier, ProjectTeamMember member)
      throws NoSuchEntityException, ValidationFailedException {
    setTenancyContext(projectIdentifier);

    try {
      com.tasktop.c2c.server.profile.domain.internal.Project project =
          profileService.getProjectByIdentifier(projectIdentifier);

      ProjectProfile projectProfile =
          profileService.getProjectProfile(project.getId(), member.getProfile().getId());

      // Wire in our updated roles now.
      projectProfile.setOwner(member.getRoles().contains(ProjectRole.OWNER));
      projectProfile.setUser(member.getRoles().contains(ProjectRole.MEMBER));

      profileService.updateProjectProfile(projectProfile);
    } catch (EntityNotFoundException e) {
      handle(e);
    } catch (ValidationException e) {
      handle(e);
    }
    return true;
  }