private Set<String> loadFavoriteProjectUuids(DbSession dbSession) { if (!userSession.isLoggedIn()) { return Collections.emptySet(); } List<PropertyDto> props = dbClient.propertiesDao().selectByQuery( PropertyQuery.builder() .setUserId(userSession.getUserId()) .setKey("favourite") .build(), dbSession); List<Long> favoriteDbIds = props.stream() .map(PropertyDto::getResourceId) .collect(MoreCollectors.toList(props.size())); return dbClient.componentDao().selectByIds(dbSession, favoriteDbIds).stream() .filter(ComponentDto::isEnabled) .filter(f -> f.qualifier().equals(Qualifiers.PROJECT)) .map(ComponentDto::uuid) .collect(MoreCollectors.toSet()); }
private boolean isFavourite(DbSession session, ComponentDto component) { PropertyQuery propertyQuery = PropertyQuery.builder() .setUserId(userSession.getUserId()) .setKey("favourite") .setComponentId(component.getId()) .build(); List<PropertyDto> componentFavourites = dbClient.propertiesDao().selectByQuery(propertyQuery, session); return componentFavourites.size() == 1; }
public void assertExists(String channel, String dispatcher, int userId, @Nullable ComponentDto component) { List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel)) .setComponentId(component == null ? null : component.getId()) .setUserId(userId) .build(), dbSession).stream() .filter(prop -> component == null ? prop.getResourceId() == null : prop.getResourceId() != null) .collect(MoreCollectors.toList()); assertThat(result).hasSize(1); assertThat(result.get(0).getValue()).isEqualTo("true"); }
public void assertDoesNotExist(String channel, String dispatcher, int userId, @Nullable ComponentDto component) { List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel)) .setComponentId(component == null ? null : component.getId()) .setUserId(userId) .build(), dbSession); assertThat(result).isEmpty(); } }
private void assertFavorite() { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setUserId(USER_ID) .setComponentId(COMPONENT_ID) .build(), dbSession)).hasSize(1); }
private void assertNoFavorite() { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setUserId(USER_ID) .setComponentId(COMPONENT_ID) .build(), dbSession)).isEmpty(); } }
private void assertProjectPropertyDoesNotExist(ComponentDto component, String key) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(component.getId()).setKey(key).build(), dbSession)).isEmpty(); }
private void assertProjectPropertyDoesNotExist(String key) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).setKey(key).build(), dbSession)).isEmpty(); }
public boolean hasNoFavorite(ComponentDto componentDto) { List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(PROP_FAVORITE_KEY) .setComponentId(componentDto.getId()) .build(), dbSession); return result.isEmpty(); } }
@Test public void add_a_project() { ComponentDto project = insertProjectAndPermissions(); TestResponse result = call(PROJECT_KEY); assertThat(result.getStatus()).isEqualTo(HTTP_NO_CONTENT); List<PropertyDto> favorites = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setUserId(USER_ID) .setKey("favourite") .build(), dbSession); assertThat(favorites).hasSize(1); PropertyDto favorite = favorites.get(0); assertThat(favorite) .extracting(PropertyDto::getResourceId, PropertyDto::getUserId, PropertyDto::getKey) .containsOnly(project.getId(), USER_ID, "favourite"); }
private void assertUserSetting(String key, String value, int userId) { List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setKey(key).setUserId(userId).build(), dbSession); assertThat(result).hasSize(1) .extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getUserId) .containsExactly(tuple(key, value, userId)); }
public boolean hasFavorite(ComponentDto componentDto, int userId) { List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(PROP_FAVORITE_KEY) .setComponentId(componentDto.getId()) .setUserId(userId) .build(), dbSession); return !result.isEmpty(); }
private void assertUserPropertyExists(String key, UserDto user) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(key) .setUserId(user.getId()) .build(), dbSession)).isNotEmpty(); }
private void assertUserPropertyExists(String key, UserDto user) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setKey(key) .setUserId(user.getId()) .build(), dbSession)).isNotEmpty(); } }
private void assertProjectPropertyExists(String key) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).setKey(key).build(), dbSession)).isNotEmpty(); }
private void assertProjectPropertyExists(String key) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).setKey(key).build(), dbSession)).isNotEmpty(); }
@Test public void add_a_file() { ComponentDto project = insertProjectAndPermissions(); ComponentDto file = db.components().insertComponent(newFileDto(project)); userSession.addProjectPermission(UserRole.USER, project, file); call(file.getDbKey()); List<PropertyDto> favorites = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() .setUserId(USER_ID) .setKey("favourite") .build(), dbSession); assertThat(favorites).hasSize(1); PropertyDto favorite = favorites.get(0); assertThat(favorite) .extracting(PropertyDto::getResourceId, PropertyDto::getUserId, PropertyDto::getKey) .containsOnly(file.getId(), USER_ID, "favourite"); }
@Test public void deactivate_user_deletes_his_properties() { logInAsSystemAdministrator(); UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); db.properties().insertProperty(newUserPropertyDto(user)); db.properties().insertProperty(newUserPropertyDto(user)); db.properties().insertProperty(newUserPropertyDto(user).setResourceId(project.getId())); deactivate(user.getLogin()); assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession)).isEmpty(); assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).setComponentId(project.getId()).build(), dbSession)).isEmpty(); }
@Test public void remove_from_org_properties() { OrganizationDto anotherOrganization = db.organizations().insert(); ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization); UserDto anotherUser = db.users().insertUser(); insertProperty("KEY_11", "VALUE", project.getId(), user.getId()); insertProperty("KEY_12", "VALUE", project.getId(), user.getId()); insertProperty("KEY_11", "VALUE", project.getId(), anotherUser.getId()); insertProperty("KEY_11", "VALUE", anotherProject.getId(), user.getId()); call(organization.getKey(), user.getLogin()); assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).build(), dbSession)) .hasSize(1).extracting(PropertyDto::getUserId).containsOnly(anotherUser.getId()); assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(anotherProject.getId()).build(), dbSession)).extracting(PropertyDto::getUserId) .hasSize(1).containsOnly(user.getId()); }
@Test public void deactivate_user_deletes_his_default_assignee_settings() { logInAsSystemAdministrator(); UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto anotherProject = db.components().insertPrivateProject(); db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setResourceId(project.getId())); db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()).setResourceId(anotherProject.getId())); db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin()).setResourceId(anotherProject.getId())); deactivate(user.getLogin()); assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().setKey("sonar.issues.defaultAssigneeLogin").build(), db.getSession())).isEmpty(); assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().build(), db.getSession())).extracting(PropertyDto::getKey).containsOnly("other"); }