use of org.sonar.api.server.ws.Response in project sonarqube by SonarSource.
the class SearchHistoryAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
SearchHistoryResponse searchHistoryResponse = Stream.of(request).map(SearchHistoryAction::toWsRequest).map(search()).map(result -> new SearchHistoryResponseFactory(result).apply()).collect(Collectors.toOneElement());
writeProtobuf(searchHistoryResponse, request, response);
}
use of org.sonar.api.server.ws.Response in project sonarqube by SonarSource.
the class UpdateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
organizationFlags.checkEnabled(dbSession);
String key = request.mandatoryParam(PARAM_KEY);
UpdateOrganizationRequest updateRequest = new UpdateOrganizationRequest(request.getParam(PARAM_NAME, (rqt, paramKey) -> wsSupport.getAndCheckName(rqt)), request.getParam(PARAM_DESCRIPTION, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckDescription(rqt))), request.getParam(PARAM_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckUrl(rqt))), request.getParam(PARAM_AVATAR_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckAvatar(rqt))));
OrganizationDto dto = getDto(dbSession, key);
userSession.checkPermission(ADMINISTER, dto);
dto.setName(updateRequest.getName().or(dto::getName)).setDescription(updateRequest.getDescription().or(dto::getDescription)).setUrl(updateRequest.getUrl().or(dto::getUrl)).setAvatarUrl(updateRequest.getAvatar().or(dto::getAvatarUrl));
dbClient.organizationDao().update(dbSession, dto);
dbSession.commit();
writeResponse(request, response, dto);
}
}
use of org.sonar.api.server.ws.Response in project sonarqube by SonarSource.
the class SetAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectKey = request.mandatoryParam(PARAM_PROJECT);
List<String> tags = request.mandatoryParamAsStrings(PARAM_TAGS).stream().filter(StringUtils::isNotBlank).map(t -> t.toLowerCase(Locale.ENGLISH)).map(SetAction::checkTag).distinct().collect(Collectors.toList());
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = componentFinder.getByKey(dbSession, projectKey);
checkRequest(project.isRootProject(), "Component must be a project");
userSession.checkComponentUuidPermission(UserRole.ADMIN, project.uuid());
project.setTags(tags);
dbClient.componentDao().updateTags(dbSession, project);
dbSession.commit();
indexers.forEach(i -> i.indexProject(project.uuid(), PROJECT_TAGS_UPDATE));
}
response.noContent();
}
use of org.sonar.api.server.ws.Response in project sonarqube by SonarSource.
the class BulkDeleteAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
List<String> uuids = request.paramAsStrings(PARAM_PROJECT_IDS);
List<String> keys = request.paramAsStrings(PARAM_PROJECTS);
String orgKey = request.param(ProjectsWsSupport.PARAM_ORGANIZATION);
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<OrganizationDto> org = loadOrganizationByKey(dbSession, orgKey);
List<ComponentDto> projects = searchProjects(dbSession, uuids, keys);
projects.stream().filter(p -> !org.isPresent() || org.get().getUuid().equals(p.getOrganizationUuid())).forEach(p -> componentCleanerService.delete(dbSession, p));
}
response.noContent();
}
use of org.sonar.api.server.ws.Response in project sonarqube by SonarSource.
the class WebServiceEngine method sendErrors.
private static void sendErrors(Response response, int status, List<String> errors) {
Response.Stream stream = response.stream();
if (stream instanceof ServletResponse.ServletStream) {
((ServletResponse.ServletStream) stream).reset();
}
stream.setStatus(status);
stream.setMediaType(MediaTypes.JSON);
try (JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output(), StandardCharsets.UTF_8))) {
json.beginObject();
writeErrors(json, errors);
json.endObject();
} catch (Exception e) {
// Do not hide the potential exception raised in the try block.
throw Throwables.propagate(e);
}
}
Aggregations