Search in sources :

Example 1 with PROJECT_TAGS_UPDATE

use of org.sonar.server.es.ProjectIndexer.Cause.PROJECT_TAGS_UPDATE 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();
}
Also used : PROJECT_TAGS_UPDATE(org.sonar.server.es.ProjectIndexer.Cause.PROJECT_TAGS_UPDATE) ComponentFinder(org.sonar.server.component.ComponentFinder) StringUtils(org.apache.commons.lang.StringUtils) Collectors(org.sonar.core.util.stream.Collectors) DbSession(org.sonar.db.DbSession) Request(org.sonar.api.server.ws.Request) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) UserRole(org.sonar.api.web.UserRole) WebService(org.sonar.api.server.ws.WebService) WsUtils.checkRequest(org.sonar.server.ws.WsUtils.checkRequest) Locale(java.util.Locale) Response(org.sonar.api.server.ws.Response) ProjectIndexer(org.sonar.server.es.ProjectIndexer) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) UserSession(org.sonar.server.user.UserSession) DbSession(org.sonar.db.DbSession) StringUtils(org.apache.commons.lang.StringUtils) ComponentDto(org.sonar.db.component.ComponentDto)

Aggregations

List (java.util.List)1 Locale (java.util.Locale)1 StringUtils (org.apache.commons.lang.StringUtils)1 Request (org.sonar.api.server.ws.Request)1 Response (org.sonar.api.server.ws.Response)1 WebService (org.sonar.api.server.ws.WebService)1 UserRole (org.sonar.api.web.UserRole)1 Collectors (org.sonar.core.util.stream.Collectors)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1 ComponentDto (org.sonar.db.component.ComponentDto)1 ComponentFinder (org.sonar.server.component.ComponentFinder)1 ProjectIndexer (org.sonar.server.es.ProjectIndexer)1 PROJECT_TAGS_UPDATE (org.sonar.server.es.ProjectIndexer.Cause.PROJECT_TAGS_UPDATE)1 UserSession (org.sonar.server.user.UserSession)1 KEY_PROJECT_EXAMPLE_001 (org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001)1 WsUtils.checkRequest (org.sonar.server.ws.WsUtils.checkRequest)1