use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class SearchAction method handle.
@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);
int limit = dbClient.groupDao().countByQuery(dbSession, organization.getUuid(), query);
List<GroupDto> groups = dbClient.groupDao().selectByQuery(dbSession, organization.getUuid(), query, options.getOffset(), pageSize);
List<Integer> groupIds = groups.stream().map(GroupDto::getId).collect(Collectors.toList(groups.size()));
Map<String, Integer> userCountByGroup = dbClient.groupMembershipDao().countUsersByGroups(dbSession, groupIds);
JsonWriter json = response.newJsonWriter().beginObject();
options.writeJson(json, limit);
writeGroups(json, groups, userCountByGroup, fields);
json.endObject().close();
}
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class UpdateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
int groupId = request.mandatoryParamAsInt(PARAM_GROUP_ID);
GroupDto group = dbClient.groupDao().selectById(dbSession, groupId);
checkFound(group, "Could not find a user group with id '%s'.", groupId);
Optional<OrganizationDto> org = dbClient.organizationDao().selectByUuid(dbSession, group.getOrganizationUuid());
checkFoundWithOptional(org, "Could not find organization with id '%s'.", group.getOrganizationUuid());
userSession.checkPermission(ADMINISTER, org.get());
boolean changed = false;
String newName = request.param(PARAM_GROUP_NAME);
if (newName != null) {
changed = true;
UserGroupValidation.validateGroupName(newName);
support.checkNameDoesNotExist(dbSession, group.getOrganizationUuid(), newName);
String oldName = group.getName();
group.setName(newName);
updateDefaultGroupIfNeeded(dbSession, org.get(), oldName, newName);
}
String description = request.param(PARAM_GROUP_DESCRIPTION);
if (description != null) {
changed = true;
group.setDescription(support.validateDescription(description));
}
if (changed) {
dbClient.groupDao().update(dbSession, group);
dbSession.commit();
}
writeResponse(dbSession, request, response, org.get(), group);
}
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class CreateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = support.findOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION_KEY));
userSession.checkPermission(ADMINISTER, organization);
GroupDto group = new GroupDto().setOrganizationUuid(organization.getUuid()).setName(request.mandatoryParam(PARAM_GROUP_NAME)).setDescription(request.param(PARAM_GROUP_DESCRIPTION));
// validations
UserGroupValidation.validateGroupName(group.getName());
support.validateDescription(group.getDescription());
support.checkNameDoesNotExist(dbSession, group.getOrganizationUuid(), group.getName());
dbClient.groupDao().insert(dbSession, group);
dbSession.commit();
writeResponse(request, response, organization, group);
}
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class ProjectDataLoaderMediumTest method return_file_data_from_single_project.
@Test
public void return_file_data_from_single_project() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
ComponentDto file = ComponentTesting.newFileDto(project, null, "file");
dbClient.componentDao().insert(dbSession, file);
tester.get(FileSourceDao.class).insert(dbSession, newFileSourceDto(file).setSrcHash("123456"));
dbSession.commit();
ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setModuleKey(project.key()));
assertThat(ref.fileDataByPath(project.key())).hasSize(1);
FileData fileData = ref.fileData(project.key(), file.path());
assertThat(fileData.hash()).isEqualTo("123456");
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class ProjectDataLoaderMediumTest method return_project_settings_with_global_scan_permission.
@Test
public void return_project_settings_with_global_scan_permission() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
// Project properties
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId()));
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId()));
dbSession.commit();
ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setModuleKey(project.key()));
Map<String, String> projectSettings = ref.settings(project.key());
assertThat(projectSettings).isEqualTo(ImmutableMap.of("sonar.jira.project.key", "SONAR", "sonar.jira.login.secured", "john"));
}
Aggregations