Search in sources :

Example 6 with NotFoundException

use of org.sonar.server.exceptions.NotFoundException in project sonarqube by SonarSource.

the class IssueFinder method getByKey.

public IssueDto getByKey(DbSession session, String issueKey) {
    IssueDto issue = dbClient.issueDao().selectByKey(session, issueKey).orElseThrow(() -> new NotFoundException(format("Issue with key '%s' does not exist", issueKey)));
    userSession.checkComponentUuidPermission(UserRole.USER, requireNonNull(issue.getProjectUuid()));
    return issue;
}
Also used : IssueDto(org.sonar.db.issue.IssueDto) NotFoundException(org.sonar.server.exceptions.NotFoundException)

Example 7 with NotFoundException

use of org.sonar.server.exceptions.NotFoundException in project sonarqube by SonarSource.

the class AddUserAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        UserId user = support.findUser(dbSession, request.mandatoryParam(PARAM_USER_LOGIN));
        Optional<ComponentDto> project = support.findProject(dbSession, request);
        String organizationKey = request.param(PARAM_ORGANIZATION);
        checkArgument(!project.isPresent() || organizationKey == null, "Organization must not be set when project is set.");
        OrganizationDto org = project.map(dto -> dbClient.organizationDao().selectByUuid(dbSession, dto.getOrganizationUuid())).orElseGet(() -> Optional.ofNullable(support.findOrganization(dbSession, organizationKey))).orElseThrow(() -> new NotFoundException(String.format("Organization with key '%s' not found", organizationKey)));
        Optional<ProjectId> projectId = project.map(ProjectId::new);
        checkProjectAdmin(userSession, org.getUuid(), projectId);
        PermissionChange change = new UserPermissionChange(PermissionChange.Operation.ADD, org.getUuid(), request.mandatoryParam(PARAM_PERMISSION), projectId.orElse(null), user);
        permissionUpdater.apply(dbSession, asList(change));
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) UserId(org.sonar.server.permission.UserId) PermissionChange(org.sonar.server.permission.PermissionChange) UserPermissionChange(org.sonar.server.permission.UserPermissionChange) ComponentDto(org.sonar.db.component.ComponentDto) ProjectId(org.sonar.server.permission.ProjectId) NotFoundException(org.sonar.server.exceptions.NotFoundException) UserPermissionChange(org.sonar.server.permission.UserPermissionChange) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 8 with NotFoundException

use of org.sonar.server.exceptions.NotFoundException in project sonarqube by SonarSource.

the class QProfileFactory method setDefault.

void setDefault(DbSession dbSession, String profileKey) {
    checkRequest(StringUtils.isNotBlank(profileKey), "Profile key must be set");
    QualityProfileDto profile = db.qualityProfileDao().selectByKey(dbSession, profileKey);
    if (profile == null) {
        throw new NotFoundException("Quality profile not found: " + profileKey);
    }
    setDefault(dbSession, profile);
    dbSession.commit();
}
Also used : NotFoundException(org.sonar.server.exceptions.NotFoundException) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 9 with NotFoundException

use of org.sonar.server.exceptions.NotFoundException in project sonarqube by SonarSource.

the class SetRootAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    checkIsRoot();
    String login = request.mandatoryParam(PARAM_LOGIN);
    try (DbSession dbSession = dbClient.openSession(false)) {
        UserDto userDto = dbClient.userDao().selectByLogin(dbSession, login);
        if (userDto == null || !userDto.isActive()) {
            throw new NotFoundException(format("User with login '%s' not found", login));
        }
        if (!userDto.isRoot()) {
            dbClient.userDao().setRoot(dbSession, login, true);
            dbSession.commit();
        }
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) NotFoundException(org.sonar.server.exceptions.NotFoundException)

Example 10 with NotFoundException

use of org.sonar.server.exceptions.NotFoundException in project sonarqube by SonarSource.

the class UnsetRootAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    checkIsRoot();
    String login = request.mandatoryParam(PARAM_LOGIN);
    try (DbSession dbSession = dbClient.openSession(false)) {
        UserDto userDto = dbClient.userDao().selectByLogin(dbSession, login);
        if (userDto == null || !userDto.isActive()) {
            throw new NotFoundException(format("User with login '%s' not found", login));
        }
        checkRequest(dbClient.userDao().countRootUsersButLogin(dbSession, login) > 0, "Last root can't be unset");
        if (userDto.isRoot()) {
            dbClient.userDao().setRoot(dbSession, login, false);
            dbSession.commit();
        }
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) NotFoundException(org.sonar.server.exceptions.NotFoundException)

Aggregations

NotFoundException (org.sonar.server.exceptions.NotFoundException)12 DbSession (org.sonar.db.DbSession)6 Test (org.junit.Test)3 ComponentDto (org.sonar.db.component.ComponentDto)3 OrganizationDto (org.sonar.db.organization.OrganizationDto)3 UserDto (org.sonar.db.user.UserDto)3 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)2 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)2 Paging (org.sonar.api.utils.Paging)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1 IssueDto (org.sonar.db.issue.IssueDto)1 GroupMembershipDto (org.sonar.db.user.GroupMembershipDto)1 GroupMembershipQuery (org.sonar.db.user.GroupMembershipQuery)1 PermissionChange (org.sonar.server.permission.PermissionChange)1 ProjectId (org.sonar.server.permission.ProjectId)1 UserId (org.sonar.server.permission.UserId)1 UserPermissionChange (org.sonar.server.permission.UserPermissionChange)1