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;
}
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();
}
}
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();
}
}
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();
}
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;
}
Aggregations