@Test public void select_by_query_with_special_characters() { String groupNameWithSpecialCharacters = "group%_%/name"; underTest.insert(dbSession, newGroupDto().setName(groupNameWithSpecialCharacters).setOrganizationUuid("org1")); db.commit(); List<GroupDto> result = underTest.selectByQuery(dbSession, "org1", "roup%_%/nam", 0, 10); int resultCount = underTest.countByQuery(dbSession, "org1", "roup%_%/nam"); assertThat(result).hasSize(1); assertThat(result.get(0).getName()).isEqualTo(groupNameWithSpecialCharacters); assertThat(resultCount).isEqualTo(1); }
assertThat(underTest.selectByQuery(dbSession, "org1", null, 0, 10)) .hasSize(5) .extracting("name").containsOnly("customers-group1", "customers-group2", "customers-group3", "SONAR-ADMINS", "sonar-users"); assertThat(underTest.selectByQuery(dbSession, "org1", "", 0, 10)) .hasSize(5) .extracting("name").containsOnly("customers-group1", "customers-group2", "customers-group3", "SONAR-ADMINS", "sonar-users"); assertThat(underTest.selectByQuery(dbSession, "org1", "sonar", 0, 10)) .hasSize(2) .extracting("name").containsOnly("SONAR-ADMINS", "sonar-users"); assertThat(underTest.selectByQuery(dbSession, "org1", null, 0, 3)) .hasSize(3); assertThat(underTest.selectByQuery(dbSession, "org1", null, 3, 3)) .hasSize(2); assertThat(underTest.selectByQuery(dbSession, "org1", null, 6, 3)).isEmpty(); assertThat(underTest.selectByQuery(dbSession, "org1", null, 0, 5)) .hasSize(5); assertThat(underTest.selectByQuery(dbSession, "org1", null, 5, 5)).isEmpty();
@Override public void handle(Request request, Response response) throws Exception { int page = request.mandatoryParamAsInt(Param.PAGE); int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE); SearchOptions options = new SearchOptions() .setPage(page, pageSize); String query = defaultIfBlank(request.param(Param.TEXT_QUERY), ""); Set<String> fields = neededFields(request); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = groupWsSupport.findOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION_KEY)); userSession.checkLoggedIn().checkPermission(ADMINISTER, organization); GroupDto defaultGroup = defaultGroupFinder.findDefaultGroup(dbSession, organization.getUuid()); int limit = dbClient.groupDao().countByQuery(dbSession, organization.getUuid(), query); Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(limit); List<GroupDto> groups = dbClient.groupDao().selectByQuery(dbSession, organization.getUuid(), query, options.getOffset(), pageSize); List<Integer> groupIds = groups.stream().map(GroupDto::getId).collect(MoreCollectors.toList(groups.size())); Map<String, Integer> userCountByGroup = dbClient.groupMembershipDao().countUsersByGroups(dbSession, groupIds); writeProtobuf(buildResponse(groups, userCountByGroup, fields, paging, defaultGroup), request, response); } }
@Override public void handle(Request request, Response response) throws Exception { int page = request.mandatoryParamAsInt(Param.PAGE); int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE); SearchOptions options = new SearchOptions() .setPage(page, pageSize); String query = defaultIfBlank(request.param(Param.TEXT_QUERY), ""); Set<String> fields = neededFields(request); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = groupWsSupport.findOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION_KEY)); userSession.checkLoggedIn().checkPermission(ADMINISTER, organization); GroupDto defaultGroup = defaultGroupFinder.findDefaultGroup(dbSession, organization.getUuid()); int limit = dbClient.groupDao().countByQuery(dbSession, organization.getUuid(), query); Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(limit); List<GroupDto> groups = dbClient.groupDao().selectByQuery(dbSession, organization.getUuid(), query, options.getOffset(), pageSize); List<Integer> groupIds = groups.stream().map(GroupDto::getId).collect(MoreCollectors.toList(groups.size())); Map<String, Integer> userCountByGroup = dbClient.groupMembershipDao().countUsersByGroups(dbSession, groupIds); writeProtobuf(buildResponse(groups, userCountByGroup, fields, paging, defaultGroup), request, response); } }