Search in sources :

Example 1 with NotFoundException

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

the class CreateEventAction method getAnalysis.

private SnapshotDto getAnalysis(DbSession dbSession, CreateEventRequest request) {
    SnapshotDto analysis = dbClient.snapshotDao().selectByUuid(dbSession, request.getAnalysis()).orElseThrow(() -> new NotFoundException(format("Analysis '%s' is not found", request.getAnalysis())));
    ComponentDto project = dbClient.componentDao().selectByUuid(dbSession, analysis.getComponentUuid()).orNull();
    checkState(project != null, "Project of analysis '%s' is not found", analysis.getUuid());
    userSession.checkComponentPermission(UserRole.ADMIN, project);
    checkArgument(Qualifiers.PROJECT.equals(project.qualifier()) && Scopes.PROJECT.equals(project.scope()), "An event must be created on a project");
    return analysis;
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) NotFoundException(org.sonar.server.exceptions.NotFoundException)

Example 2 with NotFoundException

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

the class QProfileFactory method rename.

// ------------- RENAME
public boolean rename(String key, String newName) {
    checkRequest(StringUtils.isNotBlank(newName), "Name must be set");
    checkRequest(newName.length() < 100, String.format("Name is too long (>%d characters)", 100));
    DbSession dbSession = db.openSession(false);
    try {
        QualityProfileDto profile = db.qualityProfileDao().selectByKey(dbSession, key);
        if (profile == null) {
            throw new NotFoundException("Quality profile not found: " + key);
        }
        if (!StringUtils.equals(newName, profile.getName())) {
            checkRequest(db.qualityProfileDao().selectByNameAndLanguage(newName, profile.getLanguage(), dbSession) == null, "Quality profile already exists: %s", newName);
            profile.setName(newName);
            db.qualityProfileDao().update(dbSession, profile);
            dbSession.commit();
            return true;
        }
        return false;
    } finally {
        dbSession.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) NotFoundException(org.sonar.server.exceptions.NotFoundException) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 3 with NotFoundException

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

the class GroupsAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn().checkIsSystemAdministrator();
    String login = request.mandatoryParam(PARAM_LOGIN);
    int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
    int page = request.mandatoryParamAsInt(Param.PAGE);
    String queryString = request.param(Param.TEXT_QUERY);
    String selected = request.mandatoryParam(Param.SELECTED);
    GroupMembershipQuery query = GroupMembershipQuery.builder().login(login).groupSearch(queryString).membership(getMembership(selected)).pageIndex(page).pageSize(pageSize).build();
    try (DbSession dbSession = dbClient.openSession(false)) {
        UserDto user = dbClient.userDao().selectByLogin(dbSession, login);
        if (user == null) {
            throw new NotFoundException(String.format("User with login '%s' has not been found", login));
        }
        int total = dbClient.groupMembershipDao().countGroups(dbSession, query, user.getId());
        Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(total);
        List<GroupMembershipDto> groups = dbClient.groupMembershipDao().selectGroups(dbSession, query, user.getId(), paging.offset(), pageSize);
        JsonWriter json = response.newJsonWriter().beginObject();
        writeGroups(json, groups);
        writePaging(json, paging);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) GroupMembershipQuery(org.sonar.db.user.GroupMembershipQuery) GroupMembershipDto(org.sonar.db.user.GroupMembershipDto) UserDto(org.sonar.db.user.UserDto) Paging(org.sonar.api.utils.Paging) NotFoundException(org.sonar.server.exceptions.NotFoundException) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 4 with NotFoundException

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

the class ChangelogActionTest method fail_on_unknown_profile.

@Test(expected = NotFoundException.class)
public void fail_on_unknown_profile() throws Exception {
    when(profileFactory.find(any(DbSession.class), eq(QProfileRef.fromKey(XOO_P1_KEY)))).thenThrow(new NotFoundException("Profile not found"));
    wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam(PARAM_PROFILE_KEY, XOO_P1_KEY).execute();
}
Also used : DbSession(org.sonar.db.DbSession) NotFoundException(org.sonar.server.exceptions.NotFoundException) Test(org.junit.Test)

Example 5 with NotFoundException

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

the class ComponentService method componentUuids.

public Collection<String> componentUuids(DbSession session, @Nullable Collection<String> componentKeys, boolean ignoreMissingComponents) {
    Collection<String> componentUuids = newArrayList();
    if (componentKeys != null && !componentKeys.isEmpty()) {
        List<ComponentDto> components = dbClient.componentDao().selectByKeys(session, componentKeys);
        if (!ignoreMissingComponents && components.size() < componentKeys.size()) {
            Collection<String> foundKeys = Collections2.transform(components, ComponentDto::getKey);
            Set<String> missingKeys = Sets.newHashSet(componentKeys);
            missingKeys.removeAll(foundKeys);
            throw new NotFoundException("The following component keys do not match any component:\n" + Joiner.on('\n').join(missingKeys));
        }
        for (ComponentDto component : components) {
            componentUuids.add(component.uuid());
        }
    }
    return componentUuids;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) 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