*/
// Null query
- assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 1, 10))
.hasSize(5)
.extracting("name").containsOnly("customers-group1", "customers-group2", "customers-group3", "SONAR-ADMINS", "sonar-users");
// Empty query
- assertThat(underTest.selectByQuery(dbSession, textSearchQuery(""), 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, textSearchQuery(""), 1, 10))
.hasSize(5)
.extracting("name").containsOnly("customers-group1", "customers-group2", "customers-group3", "SONAR-ADMINS", "sonar-users");
// Filter on name
- assertThat(underTest.selectByQuery(dbSession, textSearchQuery("sonar"), 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, textSearchQuery("sonar"), 1, 10))
.hasSize(2)
.extracting("name").containsOnly("SONAR-ADMINS", "sonar-users");
//Filter on name and additionalClause
- assertThat(underTest.selectByQuery(dbSession, textSearchAndManagedClauseQuery("sonar", " name = 'SONAR-ADMINS'"), 0, 10))
+ assertThat(underTest.selectByQuery(dbSession, textSearchAndManagedClauseQuery("sonar", " name = 'SONAR-ADMINS'"), 1, 10))
.hasSize(1)
.extracting("name").containsOnly("SONAR-ADMINS");
// Pagination
- assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 0, 3))
- .hasSize(3);
- assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 3, 3))
- .hasSize(2);
- assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 6, 3)).isEmpty();
- assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 0, 5))
- .hasSize(5);
- assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 5, 5)).isEmpty();
+ assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 1, 3)).hasSize(3);
+ assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 2, 3)).hasSize(2);
+ assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 3, 3)).isEmpty();
+ assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 1, 5)).hasSize(5);
+ assertThat(underTest.selectByQuery(dbSession, EMPTY_QUERY, 4, 5)).isEmpty();
}
private static GroupQuery textSearchQuery(String query) {
underTest.insert(dbSession, newGroupDto().setName(groupNameWithSpecialCharacters));
db.commit();
- List<GroupDto> result = underTest.selectByQuery(dbSession, textSearchQuery("roup%_%/nam"), 0, 10);
+ List<GroupDto> result = underTest.selectByQuery(dbSession, textSearchQuery("roup%_%/nam"), 1, 10);
int resultCount = underTest.countByQuery(dbSession, textSearchQuery("roup%_%/nam"));
assertThat(result).hasSize(1);
import java.util.List;
import java.util.Optional;
import javax.annotation.CheckForNull;
-import org.apache.ibatis.session.RowBounds;
import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.Pagination;
import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.model.UserGroupNewValue;
return mapper(session).countByQuery(query);
}
- public List<GroupDto> selectByQuery(DbSession session, GroupQuery query, int offset, int limit) {
- return mapper(session).selectByQuery(query, new RowBounds(offset, limit));
+ public List<GroupDto> selectByQuery(DbSession session, GroupQuery query, int page, int pageSize) {
+ return mapper(session).selectByQuery(query, Pagination.forPage(page).andSize(pageSize));
}
public GroupDto insert(DbSession session, GroupDto item) {
GroupDto defaultGroup = defaultGroupFinder.findDefaultGroup(dbSession);
int limit = dbClient.groupDao().countByQuery(dbSession, query);
- Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(limit);
- List<GroupDto> groups = dbClient.groupDao().selectByQuery(dbSession, query, options.getOffset(), pageSize);
+ List<GroupDto> groups = dbClient.groupDao().selectByQuery(dbSession, query, page, pageSize);
List<String> groupUuids = extractGroupUuids(groups);
Map<String, Boolean> groupUuidToIsManaged = managedInstanceService.getGroupUuidToManaged(dbSession, new HashSet<>(groupUuids));
Map<String, Integer> userCountByGroup = dbClient.groupMembershipDao().countUsersByGroups(dbSession, groupUuids);
+ Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(limit);
writeProtobuf(buildResponse(groups, userCountByGroup, groupUuidToIsManaged, fields, paging, defaultGroup), request, response);
}
}