use of org.sonar.db.property.PropertyQuery in project sonarqube by SonarSource.
the class FavoriteFinder method list.
/**
* @return the list of favorite components of the authenticated user. Empty list if the user is not authenticated
*/
public List<ComponentDto> list() {
if (!userSession.isLoggedIn()) {
return emptyList();
}
try (DbSession dbSession = dbClient.openSession(false)) {
PropertyQuery dbQuery = PropertyQuery.builder().setKey(PROP_FAVORITE_KEY).setUserId(userSession.getUserId()).build();
Set<Long> componentIds = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getResourceId).collect(Collectors.toSet());
return dbClient.componentDao().selectByIds(dbSession, componentIds).stream().sorted(Comparator.comparing(ComponentDto::name)).collect(toList());
}
}
use of org.sonar.db.property.PropertyQuery in project sonarqube by SonarSource.
the class ComponentAction method isFavourite.
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;
}
Aggregations