private boolean updateLogin(DbSession dbSession, UpdateUser updateUser, UserDto userDto, List<String> messages) { String newLogin = updateUser.login(); if (!updateUser.isLoginChanged() || !validateLoginFormat(newLogin, messages) || Objects.equals(userDto.getLogin(), newLogin)) { return false; } checkLoginUniqueness(dbSession, newLogin); dbClient.propertiesDao().selectByKeyAndMatchingValue(dbSession, DEFAULT_ISSUE_ASSIGNEE, userDto.getLogin()) .forEach(p -> dbClient.propertiesDao().saveProperty(p.setValue(newLogin))); userDto.setLogin(newLogin); if (userDto.isLocal()) { userDto.setExternalLogin(newLogin); userDto.setExternalId(newLogin); } return true; }
@Test public void select_by_key_and_matching_value() { ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); db.properties().insertProperties( newComponentPropertyDto("key", "value", project1), newComponentPropertyDto("key", "value", project2), newGlobalPropertyDto("key", "value"), newComponentPropertyDto("another key", "value", project1)); assertThat(underTest.selectByKeyAndMatchingValue(db.getSession(), "key", "value")) .extracting(PropertyDto::getValue, PropertyDto::getResourceId) .containsExactlyInAnyOrder( tuple("value", project1.getId()), tuple("value", project2.getId()), tuple("value", null) ); }
private boolean updateLogin(DbSession dbSession, UpdateUser updateUser, UserDto userDto, List<String> messages) { String newLogin = updateUser.login(); if (updateUser.isLoginChanged() && validateLoginFormat(newLogin, messages) && !Objects.equals(userDto.getLogin(), newLogin)) { checkLoginUniqueness(dbSession, newLogin); dbClient.propertiesDao().selectByKeyAndMatchingValue(dbSession, DEFAULT_ISSUE_ASSIGNEE, userDto.getLogin()) .forEach(p -> dbClient.propertiesDao().saveProperty(p.setValue(newLogin))); userDto.setLogin(newLogin); return true; } return false; }