use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class GroupPermissionDaoTest method delete_global_permission_from_group.
@Test
public void delete_global_permission_from_group() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
ComponentDto project1 = db.components().insertProject(org);
db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
db.users().insertProjectPermissionOnAnyone("perm4", project1);
underTest.delete(dbSession, "perm2", group1.getOrganizationUuid(), group1.getId(), null);
dbSession.commit();
assertThatNoPermission("perm2");
assertThat(db.countRowsOfTable("group_roles")).isEqualTo(3);
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class GroupPermissionDaoTest method select_groups_by_query_with_project_permissions.
@Test
public void select_groups_by_query_with_project_permissions() {
GroupDto group1 = db.users().insertGroup();
GroupDto group2 = db.users().insertGroup();
GroupDto group3 = db.users().insertGroup();
ComponentDto project = db.components().insertProject();
ComponentDto anotherProject = db.components().insertProject();
db.users().insertProjectPermissionOnGroup(group1, SCAN_EXECUTION, project);
db.users().insertProjectPermissionOnGroup(group1, PROVISIONING, project);
db.users().insertProjectPermissionOnAnyone(USER, project);
db.users().insertProjectPermissionOnGroup(group1, SYSTEM_ADMIN, anotherProject);
db.users().insertProjectPermissionOnAnyone(SYSTEM_ADMIN, anotherProject);
db.users().insertProjectPermissionOnGroup(group3, SCAN_EXECUTION, anotherProject);
db.users().insertPermissionOnGroup(group2, SCAN);
PermissionQuery.Builder builderOnComponent = PermissionQuery.builder().setComponentUuid(project.uuid());
assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, builderOnComponent.withAtLeastOnePermission().build())).containsOnlyOnce(group1.getName());
assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, builderOnComponent.setPermission(SCAN_EXECUTION).build())).containsOnlyOnce(group1.getName());
assertThat(underTest.selectGroupNamesByQuery(dbSession, defaultOrganizationUuid, builderOnComponent.setPermission(USER).build())).containsOnlyOnce(ANYONE);
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class SuggestionsAction method getResultsOfAllQualifiers.
private List<Qualifier> getResultsOfAllQualifiers(String query) {
ComponentIndexQuery componentIndexQuery = new ComponentIndexQuery(query).setQualifiers(Arrays.asList(QUALIFIERS)).setLimit(NUMBER_OF_RESULTS_PER_QUALIFIER);
List<ComponentsPerQualifier> componentsPerQualifiers = searchInIndex(componentIndexQuery);
if (componentsPerQualifiers.isEmpty()) {
return Collections.emptyList();
}
try (DbSession dbSession = dbClient.openSession(false)) {
return componentsPerQualifiers.stream().map(qualifier -> {
List<String> uuids = qualifier.getComponentUuids();
List<ComponentDto> componentDtos = dbClient.componentDao().selectByUuids(dbSession, uuids);
List<ComponentDto> sortedComponentDtos = Ordering.explicit(uuids).onResultOf(ComponentDto::uuid).immutableSortedCopy(componentDtos);
Map<String, String> organizationKeyByUuids = getOrganizationKeys(dbSession, componentDtos);
List<Component> results = sortedComponentDtos.stream().map(dto -> dtoToComponent(dto, organizationKeyByUuids)).collect(Collectors.toList());
return Qualifier.newBuilder().setQ(qualifier.getQualifier()).addAllItems(results).build();
}).collect(Collectors.toList());
}
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class TreeAction method toWsComponent.
private static WsComponents.Component.Builder toWsComponent(ComponentDto component, OrganizationDto organizationDto, Map<String, ComponentDto> referenceComponentsByUuid) {
WsComponents.Component.Builder wsComponent = componentDtoToWsComponent(component, organizationDto, Optional.empty());
ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyResourceUuid());
if (referenceComponent != null) {
wsComponent.setRefId(referenceComponent.uuid());
wsComponent.setRefKey(referenceComponent.key());
}
return wsComponent;
}
use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.
the class TreeAction method buildResponse.
private static TreeWsResponse buildResponse(ComponentDto baseComponent, OrganizationDto organizationDto, List<ComponentDto> components, Map<String, ComponentDto> referenceComponentsByUuid, Paging paging) {
TreeWsResponse.Builder response = TreeWsResponse.newBuilder();
response.getPagingBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()).setTotal(paging.total()).build();
response.setBaseComponent(toWsComponent(baseComponent, organizationDto, referenceComponentsByUuid));
for (ComponentDto dto : components) {
response.addComponents(toWsComponent(dto, organizationDto, referenceComponentsByUuid));
}
return response.build();
}
Aggregations