import org.sonar.db.user.UserDto;
import org.sonar.server.component.ComponentCreationData;
import org.sonar.server.component.ComponentUpdater;
+import org.sonar.server.component.ProjectCreationData;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.favorite.FavoriteUpdater;
import org.sonar.server.permission.PermissionTemplateService;
ComponentCreationData componentCreationData = mock(ComponentCreationData.class);
when(componentCreationData.mainBranchComponent())
.thenAnswer((Answer<ComponentDto>) invocation -> db.components().insertPrivateProject(PROJECT_UUID, nonExistingBranch).getMainBranchComponent());
- when(componentUpdater.createWithoutCommit(any(), any(), eq(user.getUuid()), eq(user.getLogin())))
+ when(componentUpdater.createWithoutCommit(any(), new ProjectCreationData(any(), eq(user.getUuid()), eq(user.getLogin()))))
.thenReturn(componentCreationData);
when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), any(), any())).thenReturn(createdBranch);
when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), any(), eq(nonExistingBranch.getKey()))).thenReturn(true);
.setKey(DEFAULT_PROJECT_KEY)
.setName(DEFAULT_PROJECT_NAME)
.build();
- underTest.createWithoutCommit(db.getSession(), project, userDto.getUuid(), userDto.getLogin(), null, true);
+ underTest.createWithoutCommit(db.getSession(), new ProjectCreationData(project, userDto.getUuid(), userDto.getLogin(), null, true));
verify(permissionTemplateService, never()).applyDefaultToNewComponent(any(), any(), any());
}
.build();
DbSession session = db.getSession();
- ComponentCreationData componentCreationData = underTest.createWithoutCommit(session, newComponent, userDto.getUuid(), userDto.getLogin(), null, true);
+ ComponentCreationData componentCreationData = underTest.createWithoutCommit(session, new ProjectCreationData(newComponent, userDto.getUuid(), userDto.getLogin(), null, true));
List<String> permissions = db.getDbClient().userPermissionDao().selectEntityPermissionsOfUser(session, userDto.getUuid(), componentCreationData.projectDto().getUuid());
assertThat(permissions)
import org.sonar.server.almintegration.ws.ProjectKeyGenerator;
import org.sonar.server.component.ComponentCreationData;
import org.sonar.server.component.ComponentUpdater;
+import org.sonar.server.component.NewComponent;
+import org.sonar.server.component.ProjectCreationData;
import org.sonar.server.newcodeperiod.NewCodeDefinitionResolver;
import org.sonar.server.project.DefaultBranchNameResolver;
import org.sonar.server.project.ProjectDefaultVisibility;
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("import_azure_project")
.setDescription("Create a SonarQube project with the information from the provided Azure DevOps project.<br/>" +
- "Autoconfigure pull request decoration mechanism.<br/>" +
- "Requires the 'Create Projects' permission")
+ "Autoconfigure pull request decoration mechanism.<br/>" +
+ "Requires the 'Create Projects' permission")
.setPost(true)
.setSince("8.6")
.setHandler(this)
private ComponentCreationData createProject(DbSession dbSession, GsonAzureRepo repo) {
boolean visibility = projectDefaultVisibility.get(dbSession).isPrivate();
String uniqueProjectKey = projectKeyGenerator.generateUniqueProjectKey(repo.getProject().getName(), repo.getName());
- return componentUpdater.createWithoutCommit(dbSession, newComponentBuilder()
+ NewComponent newProject = newComponentBuilder()
.setKey(uniqueProjectKey)
.setName(repo.getName())
.setPrivate(visibility)
.setQualifier(PROJECT)
- .build(),
- userSession.isLoggedIn() ? userSession.getUuid() : null,
- userSession.isLoggedIn() ? userSession.getLogin() : null,
- repo.getDefaultBranchName());
+ .build();
+ ProjectCreationData projectCreationData = new ProjectCreationData(newProject, userSession.getUuid(), userSession.getLogin(), repo.getDefaultBranchName());
+ return componentUpdater.createWithoutCommit(dbSession, projectCreationData);
}
private void populatePRSetting(DbSession dbSession, GsonAzureRepo repo, ProjectDto projectDto, AlmSettingDto almSettingDto) {
import org.sonar.server.component.ComponentCreationData;
import org.sonar.server.component.ComponentUpdater;
import org.sonar.server.component.NewComponent;
+import org.sonar.server.component.ProjectCreationData;
import org.sonar.server.newcodeperiod.NewCodeDefinitionResolver;
import org.sonar.server.project.DefaultBranchNameResolver;
import org.sonar.server.project.ProjectDefaultVisibility;
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("import_bitbucketcloud_repo")
.setDescription("Create a SonarQube project with the information from the provided Bitbucket Cloud repository.<br/>" +
- "Autoconfigure pull request decoration mechanism.<br/>" +
- "Requires the 'Create Projects' permission")
+ "Autoconfigure pull request decoration mechanism.<br/>" +
+ "Requires the 'Create Projects' permission")
.setPost(true)
.setSince("9.0")
.setHandler(this)
private ComponentCreationData createProject(DbSession dbSession, String workspace, Repository repo, @Nullable String defaultBranchName) {
boolean visibility = projectDefaultVisibility.get(dbSession).isPrivate();
String uniqueProjectKey = projectKeyGenerator.generateUniqueProjectKey(workspace, repo.getSlug());
- NewComponent mainBranch = newComponentBuilder()
+ NewComponent newProject = newComponentBuilder()
.setKey(uniqueProjectKey)
.setName(repo.getName())
.setPrivate(visibility)
.setQualifier(PROJECT)
.build();
- String userUuid = userSession.isLoggedIn() ? userSession.getUuid() : null;
- String userLogin = userSession.isLoggedIn() ? userSession.getLogin() : null;
-
- return componentUpdater.createWithoutCommit(dbSession, mainBranch, userUuid, userLogin, defaultBranchName);
+ ProjectCreationData projectCreationData = new ProjectCreationData(newProject, userSession.getUuid(), userSession.getLogin(), defaultBranchName);
+ return componentUpdater.createWithoutCommit(dbSession, projectCreationData);
}
private void populatePRSetting(DbSession dbSession, Repository repo, ProjectDto projectDto, AlmSettingDto almSettingDto) {
import org.sonar.server.component.ComponentCreationData;
import org.sonar.server.component.ComponentUpdater;
import org.sonar.server.component.NewComponent;
+import org.sonar.server.component.ProjectCreationData;
import org.sonar.server.newcodeperiod.NewCodeDefinitionResolver;
import org.sonar.server.project.DefaultBranchNameResolver;
import org.sonar.server.project.ProjectDefaultVisibility;
.setPrivate(visibility)
.setQualifier(PROJECT)
.build();
- String userUuid = userSession.isLoggedIn() ? userSession.getUuid() : null;
- String userLogin = userSession.isLoggedIn() ? userSession.getLogin() : null;
-
- return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, userLogin, defaultBranchName);
+ ProjectCreationData projectCreationData = new ProjectCreationData(newProject, userSession.getUuid(), userSession.getLogin(), defaultBranchName);
+ return componentUpdater.createWithoutCommit(dbSession, projectCreationData);
}
private void populatePRSetting(DbSession dbSession, Repository repo, ProjectDto componentDto, AlmSettingDto almSettingDto) {
import org.sonar.server.component.ComponentCreationData;
import org.sonar.server.component.ComponentUpdater;
import org.sonar.server.component.NewComponent;
+import org.sonar.server.component.ProjectCreationData;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.management.ManagedProjectService;
import org.sonar.server.newcodeperiod.NewCodeDefinitionResolver;
.setPrivate(visibility)
.setQualifier(PROJECT)
.build();
+ ProjectCreationData projectCreationData = new ProjectCreationData(projectComponent, userSession.getUuid(), userSession.getLogin(), mainBranchName,
+ gitHubSettings.isProvisioningEnabled());
return componentUpdater.createWithoutCommit(
dbSession,
- projectComponent,
- userSession.getUuid(),
- userSession.getLogin(),
- mainBranchName,
- gitHubSettings.isProvisioningEnabled());
+ projectCreationData);
}
private void populatePRSetting(DbSession dbSession, Repository repo, ProjectDto projectDto, AlmSettingDto almSettingDto) {
import org.sonar.server.almintegration.ws.ProjectKeyGenerator;
import org.sonar.server.component.ComponentCreationData;
import org.sonar.server.component.ComponentUpdater;
+import org.sonar.server.component.NewComponent;
+import org.sonar.server.component.ProjectCreationData;
import org.sonar.server.newcodeperiod.NewCodeDefinitionResolver;
import org.sonar.server.project.DefaultBranchNameResolver;
import org.sonar.server.project.ProjectDefaultVisibility;
private ComponentCreationData createProject(DbSession dbSession, Project gitlabProject, @Nullable String mainBranchName) {
boolean visibility = projectDefaultVisibility.get(dbSession).isPrivate();
String uniqueProjectKey = projectKeyGenerator.generateUniqueProjectKey(gitlabProject.getPathWithNamespace());
-
- return componentUpdater.createWithoutCommit(dbSession, newComponentBuilder()
- .setKey(uniqueProjectKey)
- .setName(gitlabProject.getName())
- .setPrivate(visibility)
- .setQualifier(PROJECT)
- .build(),
- userSession.getUuid(), userSession.getLogin(), mainBranchName);
+ NewComponent newProject = newComponentBuilder()
+ .setKey(uniqueProjectKey)
+ .setName(gitlabProject.getName())
+ .setPrivate(visibility)
+ .setQualifier(PROJECT)
+ .build();
+ ProjectCreationData projectCreationData = new ProjectCreationData(newProject, userSession.getUuid(), userSession.getLogin(), mainBranchName);
+ return componentUpdater.createWithoutCommit(dbSession, projectCreationData);
}
}
import org.sonar.server.component.ComponentCreationData;
import org.sonar.server.component.ComponentUpdater;
import org.sonar.server.component.NewComponent;
+import org.sonar.server.component.ProjectCreationData;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.permission.PermissionTemplateService;
import org.sonar.server.project.ProjectDefaultVisibility;
.setQualifier(Qualifiers.PROJECT)
.setPrivate(getDefaultVisibility(dbSession).isPrivate())
.build();
- return componentUpdater.createWithoutCommit(dbSession, newProject, userUuid, userName);
+ return componentUpdater.createWithoutCommit(dbSession, new ProjectCreationData(newProject, userUuid, userName));
}
private Visibility getDefaultVisibility(DbSession dbSession) {
* - Index component in es indexes
*/
public ComponentCreationData create(DbSession dbSession, NewComponent newComponent, @Nullable String userUuid, @Nullable String userLogin) {
- ComponentCreationData componentCreationData = createWithoutCommit(dbSession, newComponent, userUuid, userLogin, null);
+ ComponentCreationData componentCreationData = createWithoutCommit(dbSession, new ProjectCreationData(newComponent, userUuid, userLogin));
commitAndIndex(dbSession, componentCreationData);
return componentCreationData;
}
* Create component without committing.
* Don't forget to call commitAndIndex(...) when ready to commit.
*/
- public ComponentCreationData createWithoutCommit(DbSession dbSession, NewComponent newComponent,
- @Nullable String userUuid, @Nullable String userLogin) {
- return createWithoutCommit(dbSession, newComponent, userUuid, userLogin, null, false);
- }
-
- public ComponentCreationData createWithoutCommit(DbSession dbSession, NewComponent newComponent,
- @Nullable String userUuid, @Nullable String userLogin, @Nullable String mainBranchName) {
- return createWithoutCommit(dbSession, newComponent, userUuid, userLogin, mainBranchName, false);
- }
-
- /**
- * Create component without committing.
- * Don't forget to call commitAndIndex(...) when ready to commit.
- */
- public ComponentCreationData createWithoutCommit(DbSession dbSession, NewComponent newComponent,
- @Nullable String userUuid, @Nullable String userLogin, @Nullable String mainBranchName, boolean isManaged) {
- checkKeyFormat(newComponent.qualifier(), newComponent.key());
- checkKeyAlreadyExists(dbSession, newComponent);
+ public ComponentCreationData createWithoutCommit(DbSession dbSession, ProjectCreationData projectCreationData) {
+ checkKeyFormat(projectCreationData.newComponent().qualifier(), projectCreationData.newComponent().key());
+ checkKeyAlreadyExists(dbSession, projectCreationData.newComponent());
long now = system2.now();
- ComponentDto componentDto = createRootComponent(dbSession, newComponent, now);
+ ComponentDto componentDto = createRootComponent(dbSession, projectCreationData.newComponent(), now);
BranchDto mainBranch = null;
ProjectDto projectDto = null;
if (isProjectOrApp(componentDto)) {
projectDto = toProjectDto(componentDto, now);
dbClient.projectDao().insert(dbSession, projectDto);
- addToFavourites(dbSession, projectDto, userUuid, userLogin);
- mainBranch = createMainBranch(dbSession, componentDto.uuid(), projectDto.getUuid(), mainBranchName);
- if (isManaged) {
- applyPublicPermissionsForCreator(dbSession, projectDto, userUuid);
+ addToFavourites(dbSession, projectDto, projectCreationData.userUuid(), projectCreationData.userLogin());
+ mainBranch = createMainBranch(dbSession, componentDto.uuid(), projectDto.getUuid(), projectCreationData.mainBranchName());
+ if (projectCreationData.isManaged()) {
+ applyPublicPermissionsForCreator(dbSession, projectDto, projectCreationData.userUuid());
} else {
- permissionTemplateService.applyDefaultToNewComponent(dbSession, projectDto, userUuid);
+ permissionTemplateService.applyDefaultToNewComponent(dbSession, projectDto, projectCreationData.userUuid());
}
} else if (isPortfolio(componentDto)) {
portfolioDto = toPortfolioDto(componentDto, now);
dbClient.portfolioDao().insert(dbSession, portfolioDto);
- permissionTemplateService.applyDefaultToNewComponent(dbSession, portfolioDto, userUuid);
+ permissionTemplateService.applyDefaultToNewComponent(dbSession, portfolioDto, projectCreationData.userUuid());
} else {
throw new IllegalArgumentException("Component " + componentDto + " is not a top level entity");
}
--- /dev/null
+package org.sonar.server.component;
+
+import javax.annotation.Nullable;
+
+public record ProjectCreationData(NewComponent newComponent, @Nullable String userUuid, @Nullable String userLogin, @Nullable String mainBranchName, boolean isManaged) {
+ public ProjectCreationData(NewComponent newComponent, @Nullable String userUuid, @Nullable String userLogin, @Nullable String mainBranchName) {
+ this(newComponent, userUuid, userLogin, mainBranchName, false);
+ }
+
+ public ProjectCreationData(NewComponent newComponent, @Nullable String userUuid, @Nullable String userLogin) {
+ this(newComponent, userUuid, userLogin, null, false);
+ }
+}
import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentCreationData;
import org.sonar.server.component.ComponentUpdater;
+import org.sonar.server.component.NewComponent;
+import org.sonar.server.component.ProjectCreationData;
import org.sonar.server.newcodeperiod.NewCodeDefinitionResolver;
import org.sonar.server.project.DefaultBranchNameResolver;
import org.sonar.server.project.ProjectDefaultVisibility;
String visibility = request.getVisibility();
boolean changeToPrivate = visibility == null ? projectDefaultVisibility.get(dbSession).isPrivate() : "private".equals(visibility);
- return componentUpdater.createWithoutCommit(dbSession, newComponentBuilder()
- .setKey(request.getProjectKey())
- .setName(request.getName())
- .setPrivate(changeToPrivate)
- .setQualifier(PROJECT)
- .build(),
- userSession.isLoggedIn() ? userSession.getUuid() : null,
- userSession.isLoggedIn() ? userSession.getLogin() : null,
- request.getMainBranchKey());
+ NewComponent newProject = newComponentBuilder()
+ .setKey(request.getProjectKey())
+ .setName(request.getName())
+ .setPrivate(changeToPrivate)
+ .setQualifier(PROJECT)
+ .build();
+ ProjectCreationData projectCreationData = new ProjectCreationData(newProject, userSession.getUuid(), userSession.getLogin(), request.getMainBranchKey());
+ return componentUpdater.createWithoutCommit(dbSession, projectCreationData);
}