use of org.sonar.api.server.ws.Request 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.Request 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.Request 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.Request 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.Request in project sonarqube by SonarSource.
the class RemovedWebServiceHandlerTest method throw_server_exception.
@Test
public void throw_server_exception() throws Exception {
Request request = mock(Request.class);
when(request.getPath()).thenReturn("/api/resources/index");
try {
RemovedWebServiceHandler.INSTANCE.handle(request, null);
fail();
} catch (ServerException e) {
assertThat(e.getMessage()).isEqualTo("The web service '/api/resources/index' doesn't exist anymore, please read its documentation to use alternatives");
assertThat(e.httpCode()).isEqualTo(410);
}
}
Aggregations