Search in sources :

Example 1 with PARAM_NAME

use of org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_NAME in project sonarqube by SonarSource.

the class RenameAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn();
    String projectKey = request.mandatoryParam(PARAM_PROJECT);
    String newBranchName = request.mandatoryParam(PARAM_NAME);
    try (DbSession dbSession = dbClient.openSession(false)) {
        ProjectDto project = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
        checkPermission(project);
        Optional<BranchDto> existingBranch = dbClient.branchDao().selectByBranchKey(dbSession, project.getUuid(), newBranchName);
        checkArgument(!existingBranch.filter(b -> !b.isMain()).isPresent(), "Impossible to update branch name: a branch with name \"%s\" already exists in the project.", newBranchName);
        dbClient.branchDao().updateMainBranchName(dbSession, project.getUuid(), newBranchName);
        dbSession.commit();
        response.noContent();
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) NewController(org.sonar.api.server.ws.WebService.NewController) BranchDto(org.sonar.db.component.BranchDto) ComponentFinder(org.sonar.server.component.ComponentFinder) BranchesWs.addProjectParam(org.sonar.server.branch.ws.BranchesWs.addProjectParam) PARAM_PROJECT(org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_PROJECT) DbSession(org.sonar.db.DbSession) Request(org.sonar.api.server.ws.Request) DbClient(org.sonar.db.DbClient) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) UserRole(org.sonar.api.web.UserRole) WebService(org.sonar.api.server.ws.WebService) PARAM_NAME(org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_NAME) Response(org.sonar.api.server.ws.Response) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) UserSession(org.sonar.server.user.UserSession) ACTION_RENAME(org.sonar.server.branch.ws.ProjectBranchesParameters.ACTION_RENAME) DbSession(org.sonar.db.DbSession) BranchDto(org.sonar.db.component.BranchDto)

Aggregations

Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Optional (java.util.Optional)1 Request (org.sonar.api.server.ws.Request)1 Response (org.sonar.api.server.ws.Response)1 WebService (org.sonar.api.server.ws.WebService)1 NewController (org.sonar.api.server.ws.WebService.NewController)1 UserRole (org.sonar.api.web.UserRole)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1 BranchDto (org.sonar.db.component.BranchDto)1 ProjectDto (org.sonar.db.project.ProjectDto)1 BranchesWs.addProjectParam (org.sonar.server.branch.ws.BranchesWs.addProjectParam)1 ACTION_RENAME (org.sonar.server.branch.ws.ProjectBranchesParameters.ACTION_RENAME)1 PARAM_NAME (org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_NAME)1 PARAM_PROJECT (org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_PROJECT)1 ComponentFinder (org.sonar.server.component.ComponentFinder)1 UserSession (org.sonar.server.user.UserSession)1