@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; }
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(); }