private Boolean matches(String query, Profile profile) {
   if (query == null) {
     return true;
   }
   query = query.toLowerCase();
   if (profile.getFirstName().toLowerCase().startsWith(query)) {
     return true;
   }
   if (profile.getLastName().toLowerCase().startsWith(query)) {
     return true;
   }
   if (profile.getUsername().toLowerCase().startsWith(query)) {
     return true;
   }
   return false;
 }
 @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();
  }