use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class ProjectStatusAction method getSnapshotThenProject.
private ProjectAndSnapshot getSnapshotThenProject(DbSession dbSession, String analysisUuid) {
SnapshotDto snapshotDto = getSnapshot(dbSession, analysisUuid);
BranchDto branchDto = dbClient.branchDao().selectByUuid(dbSession, snapshotDto.getComponentUuid()).orElseThrow(() -> new IllegalStateException(String.format("Branch '%s' not found", snapshotDto.getUuid())));
ProjectDto projectDto = dbClient.projectDao().selectByUuid(dbSession, branchDto.getProjectUuid()).orElseThrow(() -> new IllegalStateException(String.format("Project '%s' not found", branchDto.getProjectUuid())));
return new ProjectAndSnapshot(projectDto, branchDto, snapshotDto);
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class RemoveProjectAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = loadProject(dbSession, request);
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromName(request));
checkPermissions(dbSession, profile, project);
dbClient.qualityProfileDao().deleteProjectProfileAssociation(dbSession, project, profile);
dbSession.commit();
QProfileDto activatedProfile = null;
// publish change for rules in the default quality profile
QProfileDto defaultProfile = dbClient.qualityProfileDao().selectDefaultProfile(dbSession, profile.getLanguage());
if (defaultProfile != null) {
activatedProfile = defaultProfile;
}
qualityProfileChangeEventService.publishRuleActivationToSonarLintClients(project, activatedProfile, profile);
response.noContent();
}
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class ImportBitbucketCloudRepoActionTest method import_project.
@Test
public void import_project() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertBitbucketCloudAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Repository repo = getGsonBBCRepo();
when(bitbucketCloudRestClient.getRepo(any(), any(), any())).thenReturn(repo);
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("repositorySlug", "repo-slug-1").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
assertThat(result.getKey()).isEqualTo(almSetting.getAppId() + "_" + repo.getSlug());
assertThat(result.getName()).isEqualTo(repo.getName());
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
assertThat(projectDto).isPresent();
Optional<ProjectAlmSettingDto> projectAlmSettingDto = db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get());
assertThat(projectAlmSettingDto).isPresent();
assertThat(projectAlmSettingDto.get().getAlmRepo()).isEqualTo("repo-slug-1");
Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByBranchKey(db.getSession(), projectDto.get().getUuid(), "develop");
assertThat(branchDto).isPresent();
assertThat(branchDto.get().isMain()).isTrue();
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectActionTest method handle_givenDefaultBranchNamedDefault_updateDefaultBranchNameToDefault.
@Test
public void handle_givenDefaultBranchNamedDefault_updateDefaultBranchNameToDefault() {
BranchesList branchesList = new BranchesList();
Branch branch = new Branch("default", true);
branchesList.addBranch(branch);
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Project project = getGsonBBSProject();
Repository repo = getGsonBBSRepo(project);
when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(branchesList);
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectKey", "projectKey").setParam("repositorySlug", "repo-slug").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
Collection<BranchDto> branchDtos = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get());
List<BranchDto> collect = branchDtos.stream().filter(BranchDto::isMain).collect(Collectors.toList());
String mainBranchName = collect.iterator().next().getKey();
assertThat(mainBranchName).isEqualTo("default");
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class WebhookDeliveriesAction method loadFromDatabase.
private Data loadFromDatabase(@Nullable String webhookUuid, @Nullable String ceTaskId, @Nullable String projectKey, int page, int pageSize) {
Map<String, ProjectDto> projectUuidMap;
List<WebhookDeliveryLiteDto> deliveries;
int totalElements;
try (DbSession dbSession = dbClient.openSession(false)) {
if (isNotBlank(webhookUuid)) {
totalElements = dbClient.webhookDeliveryDao().countDeliveriesByWebhookUuid(dbSession, webhookUuid);
deliveries = dbClient.webhookDeliveryDao().selectByWebhookUuid(dbSession, webhookUuid, offset(page, pageSize), pageSize);
projectUuidMap = getProjectsDto(dbSession, deliveries);
} else if (projectKey != null) {
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
projectUuidMap = new HashMap<>();
projectUuidMap.put(project.getUuid(), project);
totalElements = dbClient.webhookDeliveryDao().countDeliveriesByComponentUuid(dbSession, project.getUuid());
deliveries = dbClient.webhookDeliveryDao().selectOrderedByComponentUuid(dbSession, project.getUuid(), offset(page, pageSize), pageSize);
} else {
totalElements = dbClient.webhookDeliveryDao().countDeliveriesByCeTaskUuid(dbSession, ceTaskId);
deliveries = dbClient.webhookDeliveryDao().selectOrderedByCeTaskUuid(dbSession, ceTaskId, offset(page, pageSize), pageSize);
projectUuidMap = getProjectsDto(dbSession, deliveries);
}
}
return new Data(projectUuidMap, deliveries).withPagingInfo(page, pageSize, totalElements);
}
Aggregations