Search in sources :

Example 1 with PropertyQuery

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());
    }
}
Also used : DbSession(org.sonar.db.DbSession) PropertyQuery(org.sonar.db.property.PropertyQuery) ComponentDto(org.sonar.db.component.ComponentDto)

Example 2 with PropertyQuery

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;
}
Also used : PropertyQuery(org.sonar.db.property.PropertyQuery) PropertyDto(org.sonar.db.property.PropertyDto)

Aggregations

PropertyQuery (org.sonar.db.property.PropertyQuery)2 DbSession (org.sonar.db.DbSession)1 ComponentDto (org.sonar.db.component.ComponentDto)1 PropertyDto (org.sonar.db.property.PropertyDto)1