@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(MoreCollectors.toList()); try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto project = componentFinder.getByKey(dbSession, projectKey); checkRequest(PROJECT.equals(project.qualifier()), "Component '%s' is not a project", project.getDbKey()); userSession.checkComponentPermission(UserRole.ADMIN, project); project.setTags(tags); dbClient.componentDao().updateTags(dbSession, project); projectIndexers.commitAndIndex(dbSession, singletonList(project), PROJECT_TAGS_UPDATE); } response.noContent(); }
@Test public void update_tags() { ComponentDto project = db.components().insertPrivateProject(p -> p.setTags(emptyList())); underTest.updateTags(dbSession, project.setTags(newArrayList("finance", "toto", "tutu"))); dbSession.commit(); assertThat(underTest.selectOrFailByKey(dbSession, project.getDbKey()).getTags()).containsOnly("finance", "toto", "tutu"); }
@Test public void update_index_when_project_tags_are_updated() { ComponentDto project = db.components().insertPrivateProject(p -> p.setTagsString("foo")); indexProject(project, PROJECT_CREATION); assertThatProjectHasTag(project, "foo"); project.setTagsString("bar"); db.getDbClient().componentDao().updateTags(db.getSession(), project); IndexingResult result = indexProject(project, PROJECT_TAGS_UPDATE); assertThatProjectHasTag(project, "bar"); assertThat(result.getTotal()).isEqualTo(1L); assertThat(result.getSuccess()).isEqualTo(1L); }
@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(MoreCollectors.toList()); try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto project = componentFinder.getByKey(dbSession, projectKey); checkRequest(PROJECT.equals(project.qualifier()), "Component '%s' is not a project", project.getDbKey()); userSession.checkComponentPermission(UserRole.ADMIN, project); project.setTags(tags); dbClient.componentDao().updateTags(dbSession, project); projectIndexers.commitAndIndex(dbSession, singletonList(project), PROJECT_TAGS_UPDATE); } response.noContent(); }